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
 SQL Server Development (2000)
 Please help

Author  Topic 

Jaswinder
Starting Member

8 Posts

Posted - 2007-05-05 : 06:14:50
Suppose i have a Table name Test and columns Name,spouse .

Now i want to write a select statement that should return both columns
but convert whatsoever value of spouse to null.

example

Name Spouse
a aa
b bb

then my reult should be like a,null
b,null

ie always bring both columns but replace the value of Spouse to "" or null.


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-05 : 06:22:01
[code]
select Name, spouce = NULL
from Table
[/code]


KH

Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-05 : 11:03:01
or
 select Name, spouse = ''
from Table


just increasing my post count


Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-05 : 11:07:58
dinakar: I'll do you one better at attention to minutiae and boosting post counts.

OP wanted the spouse column upper case:

select Name, Spouse = NULL
from Table




www.elsasoft.org
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-05-07 : 14:14:38
When in rome...
[CODE]SELECT Name, NULL AS Spouse
FROM Table[/CODE]
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-07 : 14:48:58
You guys are impossible!!

So why should I stay behind...Here is my attempt:

Select
Name,
NullIf(Spouse, Spouse) Spouse
From Table


Note: NULLIF() to add just extra bit of spice..ahhh..

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

- Advertisement -