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 |
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2011-09-02 : 09:30:42
|
In my stored procedure I have populated a temp table with customer information (one record per customer). At this point the temp table is almost complete, I need to populate additional 2 more fields.euemle_email varchar(255)euemle_url varchar(255) The value for these two field resides in table f01018 in a single field called euemle. Now if field euemlt (stands for type) contains a "1" then the value is an email address and need to update euemle_email, if euemlt contains a "2" then value is a url and need to update euemle_url.A customer can have both an email record and an url record.I am not sure how to do this. Thank you. |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-09-02 : 10:31:43
|
Can you do something like this? This would be for email. For url you would need to a similar update.UPDATE t SET euemle_email = f.euemleFROM #TempTable t INNER JOIN f01018 f ON f.CustomerId = t.CustomerIdWHERE f.euemlt = '1'; |
 |
|
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2011-09-02 : 10:59:11
|
Yes, I can do it in 2 steps. Was hoping for a "one step" approach. Thank you. |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-09-02 : 12:14:53
|
You can do it in one step, for example like this (not tested):UPDATE t SET euemle_email = CASE WHEN f.euemlt = '1' THEN f.euemle ELSE t.euemle_email END, euemle_url = CASE WHEN f.euemlt = '2' THEN f.euemle ELSE t.euemle_url ENDFROM #TempTable t INNER JOIN f01018 f ON f.CustomerId = t.CustomerId |
 |
|
|
|
|