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 |
|
michpaust
Starting Member
21 Posts |
Posted - 2005-05-09 : 16:18:13
|
| I have a query that searches a table and compares two columns. If there is value in column A it takes that value and outputs to a new table, if there is no value it takes the value from column B instead and outputs it to the new table. I was wondering if using the isnull function would be the way to go or is there something else I should use? The code would follow this format more or lessIf Column A is not null then populate Table X elsetake data from Column B and populate Table X. There will always be a value in Column B. Help anyone?--I don't suffer from insanity. I enjoy every minute of it.-- |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2005-05-09 : 16:24:49
|
| IsNull or coalesce would be fine in this case.insert into table(fieldname)select isnull(cola,colb) from othertable.Mike"oh, that monkey is going to pay" |
 |
|
|
SreenivasBora
Posting Yak Master
164 Posts |
Posted - 2005-05-09 : 16:30:35
|
| Update TableX Set A.MyColumn = (Case when Y.ColumnA IS NULL Then Y.ColumnB ELSE Y.ColumnA End) as ColumnDataFrom TableY as Y Join TableX as XWhere X.Id = Y.IDHope this will work for you. :-)With RegardsSreenivas Reddy B |
 |
|
|
|
|
|