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
 T-SQL

Author  Topic 

bluemagic74
Starting Member

15 Posts

Posted - 2012-01-12 : 13:21:10
I have a below columns in table

Table 1

USERID INT 4
DRUGCODE INT 2
READTYPE INT 2
STARTDAY INT 4
ENDDAY INT 4
LASTUPDATEDDAY INT 4

SAMPLE DATA

USERID, DRUGCODE , READTYPE ,STARTDAY,ENDDAY,LASTUPDATEDDAY
1,30,1,NULL,6,200
1,30,5,NULL,6,200
1,45,1,NULL,6,200

2,7,1,23,NULL,360
2,4,3,23,NULL,360

3,43,1,NULL,NULL,234

Now I want to replace the STARTDAY NULL value with ‘0’ & ENDDAY NULL value with LASTUPDATEDDAY. Please help on writing SCRIPT. Thanks!

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-12 : 13:23:59
UPDATE Table1
SET ENDDAY = LASTUPDATEDDAY
, STARTDAY = CASE WHEN STARTDAY IS NULL THEN 0 ELSE STARTDAY END

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-12 : 13:34:39
ENDDAY = COALESCE(EndDay,LASTUPDATEDDAY)
STARTDAY = COALESCE(StartDay, 0)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-12 : 13:35:40
potato patato



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -