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)
 stored procedure

Author  Topic 

vijayanto
Starting Member

16 Posts

Posted - 2009-06-02 : 01:40:58
hi friends,
i got the problem in the stored procedure
i have fields like date and quantity
for the current year i have quantity
but at the same time i want to display the quantity depending on the previous year
please give me the solution

regards,
vijay

lightsql
Starting Member

17 Posts

Posted - 2009-06-02 : 02:01:40
I don't know if i got you're problem right but you can include a WHERE clause on your select statement in coordination with BETWEEN.

Ex:
DECLARE @startdate datetime
DECLARE @enddate datetime
SET @startdate = '01/01/2009'
SET @enddate = CAST(Now() AS datetime) --This is to get the current date though you can probably omit the CAST function
SELECT * FROM TABLESample WHERE Col_Date BETWEEN @startdate AND @enddate
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-02 : 02:07:49
quote:
Originally posted by lightsql

I don't know if i got you're problem right but you can include a WHERE clause on your select statement in coordination with BETWEEN.

Ex:
DECLARE @startdate datetime
DECLARE @enddate datetime
SET @startdate = '01/01/2009'
SET @enddate = CAST(Now() AS datetime) --This is to get the current date though you can probably omit the CAST function
SELECT * FROM TABLESample WHERE Col_Date BETWEEN @startdate AND @enddate


I think NOW() is known in MySQL but not in SQL Server.
GETDATE() should work.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-02 : 02:13:27
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=126864


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

lightsql
Starting Member

17 Posts

Posted - 2009-06-02 : 02:16:31
Thanks for the correction, that is correct webfred, hehehe
Go to Top of Page
   

- Advertisement -