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
 I need data from june 6th to june 2nd?

Author  Topic 

samsun125
Yak Posting Veteran

63 Posts

Posted - 2009-06-18 : 08:25:09
Hi all,

I have one query,
i need count(sal) from table from june 6th to june 2nd.

declare @ed1 datetime
set @ed1=(((getdate()-1)-7)-1)
print @ed1 --Jun 9 2009 5:19PM

declare @sd1 datetime
set @sd1=((((getdate()-1)-7)-1)-7)
print @sd1 --Jun 2 2009 5:19PM

select sum(sal) 'Tweets' FROM emptable
WHERE date >= @sd1 and date < @ed1 and companyid=7
i am getting result:711


if manually i am writing query like:

select sum(sal) 'Tweets' FROM emptable
WHERE date between '06/02/2009 ' and '06/09/2009' and companyid=7
i am getting result=856


is this queries wrong why i am getting different values for same dates.

if any body knows please let me know.

Regards
Rama.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-18 : 08:26:58
Express the dates in YYYYMMDD format and see

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-18 : 08:36:49
select sum(sal) AS Tweets FROM emptable
WHERE date >= '20090602' and date < '20090610'
and companyid = 7



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -