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
 General SQL Server Forums
 New to SQL Server Programming
 Help with select

Author  Topic 

lucsky8
Posting Yak Master

105 Posts

Posted - 2008-06-03 : 08:25:21
Hi, i am using stored procedure with sql server 2005.

I have this table

tblReponse
intReponseId [autonumber]
strName
intT2
intT3

Here some data

1 Luc A B
2 Marc C D
3 John A
4 Kev A D
5 Pual A

I need to create a query that will take intT3 if there something in intT3 but if intT3 is empty take intT2 instead.

So for this data it will give me this:

B D A D A

Any idea thanks in advance!!




harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-06-03 : 08:27:56
By empty do you mean it is null?

Select coalesce(intT3, intT2)
from table


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-03 : 08:28:04
SELECT COALESCE(NULLIF(intT3,' '),intT2) FROM tblResponse
Go to Top of Page

lucsky8
Posting Yak Master

105 Posts

Posted - 2008-06-03 : 08:31:33
Hi tks for the quick reply i mean empty not NULL
AND for SELECT COALESCE(NULLIF(intT3,' '),intT2) FROM tblResponse

i will try it wright away!
I let know thanks!
Go to Top of Page

lucsky8
Posting Yak Master

105 Posts

Posted - 2008-06-03 : 08:34:11
Hi tks for your anwser that work perfectly
SELECT COALESCE(NULLIF(intT3,' '),intT2) FROM tblResponse


Many tks !!!!!!
I learn something COALESCE that nice
Go to Top of Page
   

- Advertisement -