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)
 Sort by two columns (each might be null at a time)

Author  Topic 

medtech26
Posting Yak Master

169 Posts

Posted - 2008-09-09 : 15:05:33

Hello,

I have a simple query that pulls data from three tables, something like this:
SELECT t1.id, t2.countA, t3.countB 
FROM t1
LEFT OUTER JOIN t2
ON t1.id=t2.id
LEFT OUTER JOIN t3
ON t1.id=t3.id
ORDER BY countA, countB
I would like to do something like:
ORDER BY countA+countB
but I keep getting an error message as one of the two might be null (only one of the two counts might be null per record result line).

Any suggestions?

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-09-09 : 15:07:52
Coalesce(CountA,0) + Coalesce(CountB,0)
Go to Top of Page

medtech26
Posting Yak Master

169 Posts

Posted - 2008-09-09 : 15:44:27
Thanks, works like charm.
Go to Top of Page
   

- Advertisement -