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 |
powellbound
Starting Member
23 Posts |
Posted - 2007-03-10 : 22:57:12
|
Long time Oracle guy here working on a SQL Server gig and have a issue referencing multiple tables in updates and deletes. In Oracle, I can do the following that is failing in SQLServer 2000.update PS_REQ_HDR a set REQ_STATUS = 'C' where BUSINESS_UNIT = 'FORDH' and REQ_ID = '0000000265' and not exists (select 'x' from PS_REQ_LINE b where a.BUSINESS_UNIT = b.BUSINESS_UNIT and a.REQ_ID = b.REQ_ID and b.CURR_STATUS <> 'C')How would I do this in SQLServer?TIA |
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2007-03-10 : 23:09:30
|
maybe something like:update aset req_status = 'c'from PS_REQ_HDR ajoin PS_REQ_LINE b on a.BUSINESS_UNIT = b.BUSINESS_UNIT and a.REQ_ID = b.REQ_IDwhere b.CURR_STATUS <> 'C' and a.BUSINESS_UNIT = 'FORDH' and a.REQ_ID = '0000000265' |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-03-11 : 01:19:25
|
I think you only need to move the UPDATE MyTablebit to becomeUPDATE MyAliasSET ...FROM MyTable AS MyAliase.g.update a set REQ_STATUS = 'C' FROM PS_REQ_HDR awhere BUSINESS_UNIT = 'FORDH' and REQ_ID = '0000000265' and not exists ( select 'x' select 1 -- Convention is to use 1 for EXISTS statements, but the optimisers may not care! from PS_REQ_LINE b where a.BUSINESS_UNIT = b.BUSINESS_UNIT and a.REQ_ID = b.REQ_ID and b.CURR_STATUS <> 'C' ) You could use a JOIN but if the relationship is one PS_REQ_HDR : many PS_REQ_LINE it may be less efficient than using EXISTSKristen |
 |
|
powellbound
Starting Member
23 Posts |
Posted - 2007-03-11 : 09:47:58
|
Kristen,Thanks so much. What would the syntax look like using a join?Dave |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-03-12 : 08:34:28
|
"What would the syntax look like using a join?"As "ehorn" posted.Kristen |
 |
|
|
|
|