开发者

Modifying a SQL query within the Select statement

I have a stored proc that is called from my asp.net page. The field "RecordUpdated" returns TRUE or FALSE. I need that column to return YES (if true) or NO (if false)

How would I do that?

SET @SQL = 'SELECT RecID, Vendor_Number, Vendor_Name, Invoice_Number, Item_Number, RecordAddDate, RecordUpdated FROM Vendor_Invoice_开发者_开发知识库Log'
SET @SQL = @SQL + ' ORDER BY Item_Number, Vendor_Number
PRINT @SQL


If all you are doing is trying to change TRUE to YES and FALSE to NO, you can do this:

select case 
  when recordupdated = true then 'YES' 
  when recordupdated = false then 'NO' 
end recordupdates ...

Of course your code doesn't actually execute, so I am uncertain why you showed lines 2 and 3.


In situations where you need to return one or the other of something when doing a SELECT, the

CASE
    WHEN true
    THEN YES
    WHEN false
    THEN NO
END AS RecordUpdated

is pretty useful.


Sounds like a job for CASE()...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜