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
 How to Use select statement during Update

Author  Topic 

jagadid
Starting Member

1 Post

Posted - 2008-02-08 : 03:39:40
How to Use select statement when using Update statement.

Eg: Update program_video set program_id=(select id from program where recordname='122'), stopnumber=stopnumber*-1 where stopnumber < 0

Thanks & Regards

Jagadeesh

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-08 : 03:51:46
This should work fine unless you have duplicate ids for recordname 122. whats the meaning of the * near stopnumber?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-08 : 03:54:37

Something like this

Update p set program_id=(select id from program where recordname='122' and keycol=p.keycol), stopnumber=stopnumber*-1
from program_video p where stopnumber < 0

Madhivanan

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

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-02-08 : 03:57:07
Are you getting any error. I don't see any error in statement you have provided.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-08 : 04:00:34
quote:
Originally posted by visakh16

This should work fine unless you have duplicate ids for recordname 122. whats the meaning of the * near stopnumber?


Multiply by -1?

Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-08 : 04:02:24
quote:
Originally posted by sunil

Are you getting any error. I don't see any error in statement you have provided.


There can by error if subquery returns more than one value

Madhivanan

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

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-02-08 : 04:09:15
Yes,there will be an error. thanks for correction.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-08 : 04:10:11
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

This should work fine unless you have duplicate ids for recordname 122. whats the meaning of the * near stopnumber?


Multiply by -1?

Madhivanan

Failing to plan is Planning to fail


oh i felt as if he missed something there
thought it was like stopnumber*somevariable-1
Go to Top of Page
   

- Advertisement -