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.
| Author |
Topic |
|
binto
Yak Posting Veteran
59 Posts |
Posted - 2010-02-09 : 06:30:38
|
| Hi AllI have following tableDeclare @T table(W_Name varchar(50),W_Hours varchar(10),W_Colour varchar(10))INSERT INTO @T (W_Name,W_Hours)SELECT 'John','35:20'UNION ALL 'Mathew','29:40'UNION ALL 'Steve','55:35'UNION ALL 'Dan','19:15'UNION ALL 'Dale','32:05'UNION ALL 'Prince','38:25'I have 'W_Hours' as Working Hours.I have to update 'W_Colour'in such a way that if W_Hours greater than 30:00 then 'W_Colour' should be 'yellow'.if W_Hours greater than 50:00 then 'W_Colour' should be 'red'.How can I compare the hours with this requirement.Please help me.Thanks & RegardsBinto Thomas |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-02-09 : 06:55:17
|
[code]update @Tset W_Colour = case when W_Hours >= '50:00' then 'red' when W_Hours >= '30:00' then 'yellow' end[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-02-09 : 07:00:25
|
[code]Declare @T table(W_Name varchar(50),W_Hours varchar(10),W_Colour varchar(10))INSERT INTO @T (W_Name,W_Hours)SELECT 'John','35:20'UNION ALL SELECT 'Mathew','29:40'UNION ALL SELECT 'Steve','55:35'UNION ALL SELECT 'Dan','19:15'UNION ALL SELECT 'Dale','32:05'UNION ALL SELECT 'Prince','38:25'select * from @Tupdate @Tset W_Colour=CASE WHEN convert(int,replace(W_Hours,':','')) > 5000 then 'red' WHEN convert(int,replace(W_Hours,':','')) > 3000 then 'yellow' ELSE W_ColourENDwhere convert(int,replace(W_Hours,':','')) > 3000select * from @T[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-02-09 : 07:01:50
|
 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
binto
Yak Posting Veteran
59 Posts |
Posted - 2010-02-09 : 07:37:27
|
| Hi khtan,Thnaks for your replay.But is there any performance problem with using the above solution.?Thanks & RegardsBinto Thomas |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-02-09 : 07:45:16
|
This is just a simple query. How many records do you have in the table ? Is the update on the actual table or table variable ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
binto
Yak Posting Veteran
59 Posts |
Posted - 2010-02-10 : 10:49:58
|
| khtan,Update will take place on temporary table.Thanks a lot for the help!!!!!!!!Thanks & RegardsBinto Thomas |
 |
|
|
|
|
|
|
|