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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-03-20 : 09:03:33
|
| Mary writes "I'm new to SQL. I'm trying to select records based on a date field selected by the user, 'todate'. I need to select records from LAST YTD, based on that date. For example, if the 'todate' was 3/5/2007, then I'd need to select records from 1/1/2006 to 3/5/2006. The following is my last attempt of many to extract the data. It runs without error, but returns no data.select PERMIT_NO,JOBVALUE, ISSUEDfrom Permit_Main where Issued > ('1/1/' || cast((year({todate})-1) as varchar)) and Issued <= ((month({todate})) || (day({todate})) || ((year({todate})-1)));" |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-20 : 09:05:00
|
| I am not sure whether that is valid T-SQL statement.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-20 : 09:28:32
|
| [code]SELECT PERMIT_NO, JOBVALUE, ISSUEDFROM Permit_MainWHERE Issued >= DATEADD(YEAR, DATEDIFF(YEAR, 0, CURRENT_TIMESTAMP), 0) AND Issued < DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 1)[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-04-02 : 05:51:57
|
| http://sql-server-performance.com/fk_datetime.aspMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|