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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to set condition for every single column

Author  Topic 

voyager838
Yak Posting Veteran

90 Posts

Posted - 2009-05-10 : 02:50:06
Hi!

I have a serious problem, that i don't find a solution for.
I have tried.


This is the main table

LogTime A B C D E
2008-10-10 00:00:00 11 2 2 3 3
2008-10-10 01:00:00 1 NULL 15 12 7
2008-10-10 02:00:00 9 5 7 NULL 3
2008-10-10 03:00:00 13 2 15 12 1

I want now to take out every columndata and let
is satisfying the condition ">10" for column A,B and C and "<5" for column D and E
So the result would look like this

LogTime A B C D E
2008-10-10 00:00:00 11 NULL NULL NULL NULL
2008-10-10 01:00:00 NULL NULL 15 12 7
2008-10-10 02:00:00 NULL NULL NULL NULL NULL
2008-10-10 03:00:00 13 NULL 15 12 NULL


Most gratefull

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-10 : 03:26:42
[code]
UPDATE YourTable
SET A=CASE WHEN A-10 > 0 THEN A ELSE NULL END,
B=CASE WHEN B-10 > 0 THEN B ELSE NULL END,
C=CASE WHEN C-10 > 0 THEN C ELSE NULL END,
D=CASE WHEN D-5 > 0 THEN D ELSE NULL END,
E=CASE WHEN E-5 > 0 THEN E ELSE NULL END
[/code]
Go to Top of Page

voyager838
Yak Posting Veteran

90 Posts

Posted - 2009-05-10 : 04:02:05
Thanks visakh16!
That seems to work perfectly.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-10 : 05:04:59
welcome
Go to Top of Page
   

- Advertisement -