Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi i have an hours and a seperate minutes columne.g. Hour 10 Minute15I now need to flag the last two hours of the day in a new columboth datatypes are INTBe great if i could get some help with this MichelleMichelle
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2014-02-04 : 05:50:30
what do you mean by "flag the last two hours of the day" ?what is the required result ?KH[spoiler]Time is always against us[/spoiler]
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2014-02-04 : 06:21:44
this?
SELECT [Hour],[Minute],CASE WHEN [Hour] > 22 THEN 1 ELSE 0 END AS FlagColFROM Table
or this?
SELECT [date],[Hour],[Minute],CASE WHEN [Hour] > (MAX([Hour]) OVER (PARTITION BY {date])-2) THEN 1 ELSE 0 END AS FlagColFROM Table
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
MichelleMabbs
Starting Member
24 Posts
Posted - 2014-02-04 : 06:32:41
Thank you works fantastically thanks :)Michelle
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2014-02-04 : 07:24:41
quote:Originally posted by MichelleMabbs Thank you works fantastically thanks :)Michelle
which one was you looking at?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
MichelleMabbs
Starting Member
24 Posts
Posted - 2014-02-04 : 08:09:05
the last soloution but they both work wellMichelle
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2014-02-10 : 08:56:47
ok cool------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs