Computed Column/UDF | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Computed Column/UDF

Hi I have a table with columns: ID, blnOccupied (as bit), blnDayTimeUseOnly (as bit)
The table is accessed by a program (the program is unable to calculate anything) through a view and so in the view i would like another column with a combination string from these rows. e.g: ID blnOccupied blnDayTimeUSeONly 1 1 1
2 0 0
etc. So the column in the view would read: "1_Occupied_DaytimeUseOnly" or "2_UnOccupied" I can see how to write this as a stored procedure but I’m wanting the column as such to create this string on the fly. Is there any way of doing this?
Thanks and i hope you understand what i was saying as well.
Something like<br /><br />CREATE VIEW CEs_View<br />AS<br />SELECT CONVERT(varchar(<img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ />, ID) <br />+ ‘_’ <br />+ (CASE WHEN blnOccupied = 1 <br />THEN ‘Occupied'<br />ELSE ‘UnOccupied'<br />END) <br />+ (CASE WHEN blnDayTimeUSeONly = 1 <br />THEN ‘_DayTimeUseOnly ‘<br />ELSE ”<br />END) AS Bed_Status<br />FROM CEsTable<br /><br />You may just be able to use CONVERT(varchar, ID) but you may get IDs truncated.<br /><br />Regards,<br /><br />Robert.<br /><br /><br /><br /><br /><br />
Thanks, that looks so easy but my mind just stopped thinking!