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)
 Case Statement

Author  Topic 

miked1978
Starting Member

25 Posts

Posted - 2008-08-26 : 08:03:10
Hey guys. I'm somewhat of a beginner in SQL and am having problems with my code.

I have a table named step5 and have about 12 columns with data. Two of those columns i just created and need to populate them with data that comes from the other columns. The 2 columms I created are called Ahead and Behind.

Ahead needs to be populated from the SVc column if the value in SVc is greater then 0.

Behind needs to be populated from the SVc column if the value in SVc is less then 0.

Can anyone help me out<

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-26 : 08:12:45
[code]
update step5
set Ahead = SVc
where Svc > 0

update step5
set Behind = SVc
where Svc < 0
[/code]



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

miked1978
Starting Member

25 Posts

Posted - 2008-08-26 : 08:16:00
quote:
Originally posted by khtan


update step5
set Ahead = SVc
where Svc > 0

update step5
set Behind = SVc
where Svc < 0


Wow that was simplier then I thought. Thanks!!!


KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-26 : 08:28:44
or you can do it in one pass


update step5
set Ahead = case when SVc > 0 then SVc else NULL end,
Behind = case when SVc < 0 then SVc else NULL end


[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 08:29:36
or do it in a single update

update step5
set Ahead = case when Svc > 0 then SVc else Ahead end,
Behind =case when Svc < 0 then SVc else Behind end


Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-26 : 08:33:04
Madhi deleted his post and i got this while opening the thread
quote:

ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/forums/post.asp, line 333




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-26 : 08:33:26
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-26 : 08:35:55
quote:
Originally posted by khtan

Madhi deleted his post and i got this while opening the thread
quote:

ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/forums/post.asp, line 333




KH
[spoiler]Time is always against us[/spoiler]




There was a problem while posting
The post didnt show my reply so I deleted it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -