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 2000 Forums
 Transact-SQL (2000)
 Complex update

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2006-10-03 : 10:49:50
I have peculiar situation here with my tables

INSTRUMENT

BOOK PAGE IID
___________________
0013 0014 1
0013 0014 2

NAMES

BOOK PAGE SEQ ROLE Id iid
___________________________________________
0013 0014 1 1 1 1
0013 0014 2 3 2 1
0013 0014 1 1 3 2
0013 0014 2 3 4 2

I want to join INSTRUMENT and NAMES table based on book and page columns to update IID column.

But my problem I have is there are 2 sets of duplicate rows in the names table (0013, 0014, 1, 1 and 0013, 0014, 2, 3) one set should be updated a value of 1 for IID and 2nd set should be update with a value of 2

Is there any way to do this

any suggestions and inputs would help

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-10-03 : 11:19:11
Something like this:

Update N
Set IID = (case when N.Seq = 1 and N.Role = 1 then 1
when N.Seq = 2 and N.Role = 3 then 2
end)
From Names N join Instrument I
on N.Book = I.Book
and N.Page = I.Page


This is ugly solution which contains hardcoded values...if you want to avoid that, you will have to change table design of INSTRUMENT table to include SEQ and ROLE fields as well.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -