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.
| Author |
Topic |
|
melon.melon
Yak Posting Veteran
76 Posts |
Posted - 2009-07-31 : 04:42:59
|
| Helloi 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 & productNamet2 has CompanyIDThe 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
|
| hiSELECT DATEADD(MONTH,-6, GETDATE()) |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-31 : 04:47:11
|
| HITry this...SELECT * FROM TABLE_NAME WHERE DATE BETWEEN DATEADD(MONTH,-6, GETDATE()) AND GETDATE()-------------------------R.. |
 |
|
|
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. |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-31 : 05:37:20
|
| HiIt seems that your date string in begin date is not in the correct format to do the conversion...-------------------------R.. |
 |
|
|
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 |
 |
|
|
|
|
|