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 |
cjdsql
Starting Member
2 Posts |
Posted - 2011-03-23 : 15:49:40
|
I'm looking for a way to replace one column in a view with the values of another column in the same view based on the conditions of the first column.My view already creates something like this:field1 field2 field3 field4123 456 abc xyz789 234 qwe rty123 578 wte popI need to replace the values in field1 with the values in field2 where field1 equals 123. And only if it equals 123. Kind of on a time crunch if anyone can help. THANKS! |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
cjdsql
Starting Member
2 Posts |
Posted - 2011-03-23 : 16:06:20
|
quote: Originally posted by tkizer UPDATE Table1SET field1 = field2WHERE field1 = 123Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Thanks for the quick reply, but this information is not in a table. The view is created from a table which has all of it information in 1 field. The view breaks it up into multiple fields. It is at this point (in the creation of the view) that I would like to do the comparison and replacement. There are several other queries that run against this 1 view. So if I fix it, I fix everything in one place.Table1 looks like this:FIELD1123456abcxyzThe view breaks in into:Field1 Field2 Field3 Field4123 456 abc xyzThen I need to compare and replace. Maybe that explains it a little better. |
 |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-03-23 : 16:48:58
|
SELECT CASE WHEN field1=123 THEN field2 ELSE field1 ENDFROM myView |
 |
|
|
|
|