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)
 select query

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2005-01-16 : 14:41:28
Hi,

I have a table with 2 fields:

passport varchar
idNo numeric


I have to display the fields in one column
If idNo is null then I want to show the passport number in the column but if neither passport or idNo are null then I want to show the idNo.

I tried the following select query but it only works if both fields are numeric and i can't change the data type for one of the fields as it will coz huge problems:
select idno,passport,
(case when idno is null then passport else idno end) as sid
from student

How can I make it work with different data types?

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-16 : 17:39:28
select idno,passport,
sid = coalesce(convert(varchar(20),idno),passport)
from student


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2005-01-17 : 02:15:02
Thanks. That worked great
Go to Top of Page
   

- Advertisement -