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)
 date selection

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, ISSUED

from 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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-20 : 09:28:32
[code]SELECT PERMIT_NO,
JOBVALUE,
ISSUED
FROM Permit_Main
WHERE Issued >= DATEADD(YEAR, DATEDIFF(YEAR, 0, CURRENT_TIMESTAMP), 0)
AND Issued < DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 1)[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-02 : 05:51:57
http://sql-server-performance.com/fk_datetime.asp

Madhivanan

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

- Advertisement -