question

rasheet avatar image
rasheet asked

ABOUT VIEW

hi, i have a table with many columns. in one column there are time values and in an other column there are characters like a and b. this means a time depends a and th other depends b. i want a view with two columns at column a there will be a values and in b column there will be b values. is it possible
view
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
OK, here's a quick & dirty script that shows something like what I think you're after: DECLARE @foo TABLE (RowID INT IDENTITY, CharField CHAR(1), TimeField DATETIME) INSERT INTO @foo (CharField, TimeField) SELECT 'a',GETDATE() UNION ALL SELECT 'b',GETDATE()-1 UNION ALL SELECT 'a', GETDATE()+1 SELECT *, CASE WHEN charfield='a' THEN Timefield ELSE NULL END AS TimeA, CASE WHEN charfield='b' THEN Timefield ELSE NULL END AS TimeB FROM @foo Run that code and you'll see a column TimeA that contains the TimeField value only when the CharField value is 'a', and TimeB when charfield value is 'b' That final `SELECT` - that's the bit you'll need to alter to suit your requirements. When you've got that working as you require, then wrap it in a `VIEW`.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

thanks thomasrushton i will try it...
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.