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)
 Filter records prior to current date

Author  Topic 

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-07-31 : 04:42:59
Hello

i need to get t1 with filtering of the BDate for 1st 6 mths from current system date and this has to be sorted by productName..how can this be done from this query:

t1 has CompanyID, BDate & productName
t2 has CompanyID

The current system date can be retrieved:
select getdate()

select * from t1 d,t2 u
where d.CompanyID=u.CompanyID order by d.productName ASC

WoodHouse
Posting Yak Master

211 Posts

Posted - 2009-07-31 : 04:44:32
hi

SELECT DATEADD(MONTH,-6, GETDATE())
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-31 : 04:47:11
HI

Try this...
SELECT * FROM TABLE_NAME WHERE DATE BETWEEN DATEADD(MONTH,-6, GETDATE()) AND GETDATE()

-------------------------
R..
Go to Top of Page

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-07-31 : 05:31:34
quote:

Try this...
SELECT * FROM TABLE_NAME WHERE DATE BETWEEN DATEADD(MONTH,-6, GETDATE()) AND GETDATE()



Need to cast "Date" in nvarchar(50) to read as date as there is
this error
Arithmetic overflow error converting expression to data type datetime.
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-31 : 05:37:20
Hi

It seems that your date string in begin date is not in the correct format to
do the conversion...

-------------------------
R..
Go to Top of Page

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-07-31 : 06:06:25
In that case...can i filter the BMonth and BYear instead of using Date according to current Month & Year?
BMonth - nvarchar(10)
BYear - int
Go to Top of Page
   

- Advertisement -