October 31, 2003 at 11:28 pm
Hi, I'm quite new to SQL and could use your help please.
In my database I have 2 tables that hold unique values, and I need to 'Map' all these values from one table to a single value in the other table. Obviously if I do a normal update statement, then I can't enter another value the same?
November 1, 2003 at 1:37 am
No idea what you want - can you give an example.
Cursors never.
DTS - only when needed and never to control.
Cursors never.
DTS - only when needed and never to control.
November 1, 2003 at 3:42 am
Thank you for your reply - I'm trying to do the following:
Update dbo.table
set c_alias = 'Test'
where c_alias = 'Work', 'Book', 'Event' etc
Regards
November 3, 2003 at 6:25 am
Update dbo.table
set c_alias = 'Test'
where c_alias IN ('Work', 'Book', 'Event')
This will replace c_alias with Test where it is either Work,Book or Event. Is this what you wanted?
Far away is close at hand in the images of elsewhere.
Anon.
November 3, 2003 at 6:51 am
Hi Steve,
I'm still not sure I understand what you need to do... but I'll try.
To update just one independent table:
UPDATE dbo.table
SET c_alias = 'Test'
WHERE c_alias IN ('Work', 'Book', 'Event')
This simply replaces any of the values 'Work', 'Book' or 'Event' with value 'Test'.
To update table1 depending on values in some other table (table2):
UPDATE dbo.table1
SET c_alias = 'Test'
FROM dbo.table1 t1
JOIN dbo.table2 t2 ON t2.key = t1.key
WHERE t2.c_alias IN ('Work', 'Book', 'Event')
This updates column c_alias to 'Test' in all records of table1, where the same column in a corresponding record of table2 has value 'Work', 'Book' or 'Event'. Of course supposing that these tables can be joined on some column(s), here represented by "key".
The "IN" can be defined by naming the values (as above) or e.g. by selecting them from another table (as below - hypothetical example).
WHERE t2.c_alias IN (select type from dbo.table_of_types where status = '2')
Hope it helps.. If that's not what you need to do, please explain your problem in more detail.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply