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)
 IsNull question

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 less
If Column A is not null then populate Table X else
take 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"
Go to Top of Page

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 ColumnData
From TableY as Y Join TableX as X
Where X.Id = Y.ID

Hope this will work for you. :-)


With Regards
Sreenivas Reddy B
Go to Top of Page
   

- Advertisement -