我已通過SO搜索,但未找到任何有助於解決問題的內容。我不知道如何解釋有關我的查詢的錯誤消息。TSQL錯誤:在期望條件的上下文中指定的非布爾類型的表達式
我的查詢是:
select AST_ID,
case when CRA_StatusID=1 then 'Wait on Info'
when CRA_StatusID=2 then 'Wait PrePay'
when CRA_StatusID=3 then 'Acquire Chart'
when CRA_StatusID=4 then 'Copy Chart'
when CRA_StatusID=5 then 'Need Invoice'
when CRA_StatusID=6 then 'Wait Payment'
when CRA_StatusID=7 then 'Ready for Delv' else 'Complete' end as AST_Status,
case when AST_WOPrinted is null then '' else 'Y' end as AST_WOPrinted,
case when AST_DeliveryDate is null then '' else 'Y' end as AST_Delivered,
AST_PatientLName+'', ''+AST_PatientFName+' '+AST_PatientMName as PatientName,
case when len(AST_RequestorName) > 0 then AST_RequestorName else AST_RequestorContact end as AST_RequestorName,
AST_Created,AST_ProviderName
from dbo.AST
inner join dbo.fnASTCurrentStatus() on AST_ID=CRA_ASTID
where ' + @WhereClause + '
union all
select AST_ID,
case
when CRA_StatusID=1 then 'Wait on Info'
when CRA_StatusID=2 then 'Wait PrePmt'
when CRA_StatusID=3 then 'Aquire Chart'
when CRA_StatusID=4 then 'Copy Chart'
when CRA_StatusID=5 then 'Need Invc'
when CRA_StatusID=6 then 'Wait Pmt'
when CRA_StatusID=7 then 'Ready for Delv' else 'Complete'
end as AST_Status,
case when AST_WOPrinted is null then '' else 'Y' end as AST_WOPrinted,
case when AST_DeliveryDate is null then '' else 'Y' end as AST_Delivered,
AST_PatientLName+'', ''+AST_PatientFName+' '+AST_PatientMName as PatientName,
case when len(AST_RequestorName) > 0 then AST_RequestorName else AST_RequestorContact end as AST_RequestorName,
AST_Created,AST_ProviderName
from dbo.Archive_AST
inner join dbo.fnArchiveASTCurrentStatus() on AST_ID=CRA_ASTID
where ' + @WhereClause + '
set @WhereClause=' AST_ProviderID in (select ProviderID from dbo.UserProvider where CSA_UserID = ' + convert(varchar,55) + ')'
錯誤信息上寫着:
An expression of non-boolean type specified in a context where a condition is expected, near 'union'.
An expression of non-boolean type specified in a context where a condition is expected, near ' + @WhereClause + '.
我怎樣才能解決這個錯誤嗎?
'where'+ @WhereClause +''不是有效的where子句..? – thebjorn 2014-09-23 19:49:24
@whereClause在存儲過程中單獨定義。 – user3929962 2014-09-23 19:54:14
@where的價值是什麼?只是一個例子,所以我們可以理解它的樣子。但是,是的,比爾森是正確的,你的條款是無效的 – SQLChao 2014-09-23 19:55:58