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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help with flag last two hours

Author  Topic 

MichelleMabbs
Starting Member

24 Posts

Posted - 2014-02-04 : 05:28:17
Hi i have an hours and a seperate minutes column

e.g.

Hour
10
Minute
15

I now need to flag the last two hours of the day in a new colum

both datatypes are INT

Be great if i could get some help with this

Michelle

Michelle

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]

Go to Top of Page

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 FlagCol
FROM Table


or this?

SELECT [date],[Hour],[Minute],CASE WHEN [Hour] > (MAX([Hour]) OVER (PARTITION BY {date])-2) THEN 1 ELSE 0 END AS FlagCol
FROM Table



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

MichelleMabbs
Starting Member

24 Posts

Posted - 2014-02-04 : 06:32:41
Thank you works fantastically thanks :)

Michelle
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

MichelleMabbs
Starting Member

24 Posts

Posted - 2014-02-04 : 08:09:05
the last soloution but they both work well

Michelle
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-10 : 08:56:47
ok cool

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -