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 |
|
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 < 0Thanks & RegardsJagadeesh |
|
|
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? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-08 : 03:54:37
|
| Something like thisUpdate p set program_id=(select id from program where recordname='122' and keycol=p.keycol), stopnumber=stopnumber*-1 from program_video p where stopnumber < 0MadhivananFailing to plan is Planning to fail |
 |
|
|
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. |
 |
|
|
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?MadhivananFailing to plan is Planning to fail |
 |
|
|
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 valueMadhivananFailing to plan is Planning to fail |
 |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-02-08 : 04:09:15
|
| Yes,there will be an error. thanks for correction. |
 |
|
|
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?MadhivananFailing to plan is Planning to fail
oh i felt as if he missed something therethought it was like stopnumber*somevariable-1 |
 |
|
|
|
|
|