Re: Please help with SQL Statement
- From: "Tom Moreau" <tom@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 15:14:58 -0400
Yep. You can have an ORDER BY with an expression:
order by
isnull ([Order], 0)
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
..
"Conan Kelly" <CTBarbarin at msn dot com> wrote in message
news:%23ZQV6txYGHA.4168@xxxxxxxxxxxxxxxxxxxxxxx
Tom,
Thank you for your help. That did it. I keep for getting about "IS" when
checking for NULL.
So 13 show up instead of null, but the qurey did not sort this correctly.
13 is at the top and then 1-12 below. So I'm assuming
that even though I'm forcing a 13, SQL Server still sees it as NULL and
sorts it as such. Is this correct? Is there any way I can
get it to sort it as 13?
Thanks again for all of your help,
Conan
"Tom Moreau" <tom@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23I22WfxYGHA.444@xxxxxxxxxxxxxxxxxxxxxxx
You must use IS NULL to compare something with NULL:
SELECT case when [Order] IS NULL then 13 else [Order] end, [Product
Roll-Up],...
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Conan Kelly" <CTBarbarin at msn dot com> wrote in message
news:e1qHJaxYGHA.2136@xxxxxxxxxxxxxxxxxxxxxxx
Hello all,
I'm sorry if this is not an appropriate NG to post this question to. I
looked for one and nothing jumped out at me.
I have a SQL statement goes something like this:
SELECT [Order], [Product Roll-Up],
sum(case [File Date] when '12/31/02' then [Balance] end) as '12/31/02',
sum(case [File Date] when '1/31/03' then [Balance] end) as '1/31/03',
...
...
...
... as '3/31/06'
FROM View1
GROUP BY [Order], [Product Roll-Up]
ORDER BY [Order], [Product Roll-Up]
The results in the [Order] field will be NULL in the first row and 1
through
12 in the following rows.
What I want to do is set this up so that it will return 13 instead of
NULL.
I tried the following select statement but it didn't work:
SELECT case [Order] when NULL then 13 else [Order] end, [Product
Roll-Up],...
Is there any way to accomplish what I'm trying to do by editing the SQL
statement similar to how I did above?
Thanks for any help anyone can provide,
Conan Kelly
ps. please let me know of a better NG to post questions like this to.
.
- References:
- Please help with SQL Statement
- From: Conan Kelly
- Re: Please help with SQL Statement
- From: Tom Moreau
- Re: Please help with SQL Statement
- From: Conan Kelly
- Please help with SQL Statement
- Prev by Date: Re: Please help with SQL Statement
- Next by Date: Re: What is wrong with this transformation?
- Previous by thread: Re: Please help with SQL Statement
- Next by thread: Re: What is wrong with this transformation?
- Index(es):
Relevant Pages
|