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
 General SQL Server Forums
 New to SQL Server Programming
 Is this correct?

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-15 : 13:17:25

I want to add the TotalFO and the TotalDDs colums (and call that column TotalPend250) together to get the count of how many cases are pending between 250 - 300 using getdate()

Is this correct?

select sum(TotalFO) + sum(TotalDDS) as TotalPend250
from T16Pendall
where DATEDIFF(day, TotalPend250, GETDATE()) > 250 and DATEDIFF(day, TotalPend250, GETDATE()) < 300

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2010-10-15 : 14:06:01
Have no idea what TotalFO and TotalDDs columns represent or their datatypes so I don't know if that is "correct" but just to translate your statement into something syntactically correct:

select sum(TotalFO) + sum(TotalDDS) as TotalPend250
from T16Pendall
having DATEDIFF(day, sum(TotalFO) + sum(TotalDDS), GETDATE()) > 250
and DATEDIFF(day, sum(TotalFO) + sum(TotalDDS), GETDATE()) < 300


Be One with the Optimizer
TG
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-15 : 15:00:58
TG thanks for your response. I'm sorry I left out those datatypes. They are char(1) for TotalFO and TotalDDS. Thanks for cleaning it all up for me.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2010-10-15 : 15:13:38
your welcome but...
So your SUMming a char(1) value? won't you get a "char is invald for sum operator" error?

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-15 : 15:23:58
NO

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2010-10-15 : 18:09:29
quote:
Originally posted by X002548

NO


Well stated and a good argument. But I get that error.

select sum([col])
from (
select convert(char(1), 1) as [col] union all
select convert(char(1), 2)
) d

OUTPUT:
Msg 8117, Level 16, State 1, Line 1
Operand data type char is invalid for sum operator.


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -