本文介绍了如何解决此错误(为变量赋值的SELECT语句不得与数据检索操作结合使用。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 DECLARE @parameter int 推荐答案 CASE WHEN condition THEN value你的SELECT不评估为布尔值,所以SQL正确地抱怨。your SELECTs do not evaluate to a boolean, so SQL rightly complains. declare @tempTable table (profileID int, fullname varchar(100))insert into @tempTableselect U.ProfileID,Case when (P.ProfileCategoryID in (2546 , 2547) AND P.ProfileID=@parameter)Then( SELECT DISTINCT U.fullname FROM TM_profile P JOIN TM_User U ON U.ProfileID= P.ProfileID WHERE P.ProfileCategoryID IN (2545,2544,2543) AND U.Is_Active=1)when (P.ProfileCategoryID=2544 AND P.profileid=@parameter)Then( SELECT DISTINCT U.FullName FROM TM_profile P JOIN TM_User U ON U.ProfileID= P.ProfileID WHERE P.ProfileCategoryID IN (2543) AND U.Is_Active=1)When (P.ProfileCategoryID=2545 AND P.profileid=@parameter)Then( SELECT DISTINCT U.FullName FROM TM_profile P JOIN TM_User U ON U.ProfileID= P.ProfileID WHERE P.ProfileCategoryID IN (2544,2543) AND U.Is_Active=1)When ( P.ProfileCategoryID=2543 AND P.profileid=@parameter )Then( SELECT distinct FullName FROM TM_profile P join TM_User U on U.ProfileID= P.ProfileID WHERE P.ProfileCategoryID in (2544) and U.Is_Active=1)ENDfrom TM_User UJOIN TM_profile P ON U.ProfileID= P.ProfileIDwhere U.TM_UserID=106select * from @tempTable 我不知道您的数据库设计的情况,但请确保设计是正确的,以防止出于报告目的或任何其他目的而将数据输出的进一步障碍... 快乐编码.. !! -Nayan I don't know your circumstances for the DB design but please make sure the design is correct in order to prevent further hurdles in getting the data out for reporting purposes or any other purposes if any...Happy coding..!!-Nayan when (P.ProfileCategoryID=2544 AND P.profileid=@parameter)Then( SELECT DISTINCT U.FullName FROM TM_profile P JOIN TM_User U ON U.ProfileID= P.ProfileID WHERE P.ProfileCategoryID IN (2543) AND U.Is_Active=1) 您似乎想根据另一个ID获取不同的全名。如果这是正确的,它肯定是神秘的,并且表明你的数据库坏了 其次,你就是不能像这样嵌套一个选择。这是行不通的。语法是完全错误和破坏的。您需要发布一个新问题,解释您的数据结构(最好使用脚本来创建和填充表格以便我们为您提供帮助),以及您正在尝试做什么。 这看起来像你随机做了一些东西。You seem to want to grab a different full name based on another id. If this is correct, it's certainly arcane and an indication that your DB is brokenSecondly, you just cannot nest a select like this. It does not work. The syntax is utterly wrong and broken. You need to post a new question, explaining your data structure ( preferably with scripts to create and populate the tables so we can help you ), and what it is you're trying to do.This looks like you made something up at random. 这篇关于如何解决此错误(为变量赋值的SELECT语句不得与数据检索操作结合使用。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 16:06