David that kinda of worked. below is my revised query.
SELECT
CASE Datepart(dw,OrderDate) WHEN '1' THEN Count(OrderDate) ELSE 0 END AS
OPD_01,
CASE Datepart(dw,OrderDate) WHEN '2' THEN Count(OrderDate) ELSE 0 END AS
OPD_02,
CASE Datepart(dw,OrderDate) WHEN '3' THEN Count(OrderDate) ELSE 0 END AS
OPD_03,
CASE Datepart(dw,OrderDate) WHEN '4' THEN Count(OrderDate) ELSE 0 END AS
OPD_04,
CASE Datepart(dw,OrderDate) WHEN '5' THEN Count(OrderDate) ELSE 0 END AS
OPD_05,
CASE Datepart(dw,OrderDate) WHEN '6' THEN Count(OrderDate) ELSE 0 END AS
OPD_06,
CASE Datepart(dw,OrderDate) WHEN '7' THEN Count(OrderDate) ELSE 0 END AS
OPD_07
FROM Orders
WHERE Status = 'SHIPPED'
AND (OrderDate BETWEEN '#VarStartDate# 00:00:00' AND
'#VarEndDate#
23:59:59')
GROUP BY Datepart(dw,OrderDate)
when dumped, it yields...
OPD_01 OPD_02 OPD_03 OPD_04 OPD_05 OPD_06 OPD_07
0 0 5 0 0 0 0
0 0 0 7 0 0 0
is there any way to get this all on on line? i guess its NOT being grouped
correctly.
~Che
-----Original Message-----
From: David Fafard [mailto:[EMAIL PROTECTED]
Sent: Monday, March 07, 2005 9:27 AM
To: CF-Talk
Subject: Re: SQL Case Question?
try something along the lines of:
case datepart( d, OrderDate ) when '1' then count( OrderDate ) else 0 end as
day_01,
case datepart( d, OrderDate ) when '2' then count( OrderDate ) else 0 end as
day_02,
case datepart( d, OrderDate ) when '3' then count( OrderDate ) else 0 end as
day_03,
etc...
That should force a zero into a day.
Dave
----- Original Message -----
From: "Che Vilnonis" <[EMAIL PROTECTED]>
To: "CF-Talk" <[email protected]>
Sent: Monday, March 07, 2005 8:47 AM
Subject: RE: SQL Case Question?
tried isNull(), then did a dump of the query.
i got results for sunday and monday...yet nothing (not even any zeroes)
for the rest of the week. any other ideas?
-----Original Message-----
From: Ali Awan [mailto:[EMAIL PROTECTED]
Sent: Friday, March 04, 2005 5:32 PM
To: CF-Talk
Subject: RE: SQL Case Question?
There is a function in SQL called IsNull which replaces a NULL result with
whatever value you specify.
Try doing this in the first line of your statement:
SELECT IsNull(Count(OrderDate),0) AS TotalOrdersPerDay
That way if the result set is NULL it will output a 0.
Ali
-----Original Message-----
From: Che Vilnonis [mailto:[EMAIL PROTECTED]
Sent: Friday, March 04, 2005 2:23 PM
To: CF-Talk
Subject: OT: SQL Case Question?
I'm trying to output total orders by day of the week.
SELECT Count(OrderDate) AS TotalOrdersPerDay
FROM Orders
WHERE Status = 'SHIPPED'
AND (OrderDate BETWEEN '#VarStartDate# 00:00:01' AND '#VarEndDate#
23:59:59')
GROUP BY Datepart(dw,OrderDate)
ORDER BY Datepart(dw,OrderDate) ASC
This code works great, for the most part. How would I change this code so
that if there were NO orders for a particular day, the query would return a
result of zero [0] and not null or whatever it returns when there is no
result? Does this make sense? I just don't want to have <td> cells with
nothing in them.
Thanks, Che
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:197670
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54