November 11, 2015 at 8:29 am
I am getting an error due to conversion at this part of the script.. if i remove this case it works but i need it in.. how do i apply a conversion so sort it out?
Msg 245, Level 16, State 1, Line 5
Conversion failed when converting the varchar value 'yes' to data type bit.
Cheers!
Case
when status_ID = 0 and flg_attendance = 'yes' then '38'
when status_ID = 0 and flg_attendance = 'no' then null
--when status_ID = 0 and flg_attendance = 0 then null
when status_ID = 1 then 28
when status_ID = 2 then 31
when status_ID = 3 then 32
when status_ID = 4 then 33
when status_ID = 5 then 31
end
as StatusID,
November 11, 2015 at 8:36 am
What data type is flg_attendance?
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
November 11, 2015 at 8:43 am
flg_attendance is bit
status_ID is int
November 11, 2015 at 8:51 am
SQLAssAS (11/11/2015)
flg_attendance is bitstatus_ID is int
Then you need to check for 1, 0 or NULL (Those are the only values a bit can have).
when status_ID = 0 and flg_attendance = 1 then '38'
when status_ID = 0 and flg_attendance = 0 then null
...
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply