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 2000 Forums
 Transact-SQL (2000)
 Help on dates

Author  Topic 

sqlboss
Starting Member

2 Posts

Posted - 2006-07-24 : 22:45:43
First Query:
I have to compare two dates and write T-SQL stored procedure based on the conditions

1. From Date and End date != 01/01/1888
2. If From date > End Date, send No
else if from date <= end date, send Yes

Second Query:
The other query is to check if end date > 1 year, send yes else no

Please help!

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-07-24 : 22:50:56
Homework?


CODO ERGO SUM
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-07-24 : 23:16:16
open books online,
type "datetime data type, datetime functions"
search also for "between" and "case"

try to construct a tsql from these and post it here if the result is not as you expected it to be

--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-29 : 06:39:02
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-01 : 03:46:12
The "one year thing" is a little bit tricky...

DECLARE @FromDate DATETIME,
@ToDate DATETIME

SELECT @FromDate = '20050923',
@ToDate = '20060719'

SELECT CASE
WHEN @FromDate = '18880101' AND @ToDate = '18880101' THEN 'Not valid date'
WHEN @FromDate > @ToDate THEN 'No'
ELSE 'Yes'
End 'First query',
CASE
WHEN @FromDate BETWEEN DATEADD(year, -1, @ToDate) AND DATEADD(year, 1, @ToDate) THEN 'No'
ELSE 'Yes'
END 'Second query'

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -