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 2005 Forums
 Transact-SQL (2005)
 Variable field

Author  Topic 

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2009-02-09 : 08:51:06
Hi, I got a SP where it does something like:

select
...
[Headlinedate]
...
[Publishdate]
Order by
[Headlinedate]

But since headlinedate was not required up until now, headlinedate might return a NULL.
So when it returns a NULL, I want to replace it with [publishdate] which always has a value.

Can I do something like:

select
...
if headlinedate <> null
headlinedate
else
publishdate
end if
....
order by
if headlinedate <> null
headlinedate
else
publishdate
end if



The secret to creativity is knowing how to hide your sources. (Einstein)

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-09 : 08:55:49
yeah, You could do that. Just use the right syntax...

select 
...
ISNULL([Headlinedate],[publishdate])
...
from
..
order by
ISNULL([Headlinedate],[publishdate]),
...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-09 : 09:49:43
also see this (not much pronounced in this situation though)

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx
Go to Top of Page
   

- Advertisement -