You are here: Re: Date creation in SQL « MsSQL Server « IT news, forums, messages
Re: Date creation in SQL

Posted by Erland Sommarskog on 05/04/06 00:10

wgblackmon@yahoo.com (wgblackmon@yahoo.com) writes:
> I have a parameter that is being input as a String via Crystal Reports.
> It's called 'School Year'
> and a typical value is '2006'. I need to be able to create a 'Date'
> that is compared to a field value in a where clause. In this case the
> db field is called 'requisition_time_stamp' in the T_ORDER table. The
> 'requistion_time_stamp' file is of type 'datetime'.
>
> Below is pseudo_code for what I need to do:
>
> T_ORDER.requisition_time_stamp >= Date(ToNumber(School Year),6,1)
> AND
> T_ORDER.requisition_time_stamp < Date(ToNumber(School Year + 1) , 6,
> 1)

It's as simple as:

T_ORDER.requisition_time_stamp >= @year + '0101'
T_ORDER.requisition_time_stamp < dateadd(DAY, 1, @year + '1231')

YYYYMMDD is one of the few date formats that are always interpreted
the same in SQL Server.

> I've looked at the Date functions in the Sybase documentation and I
> don't see anything that fits what I'm trying to do.

Sybase? This newsgroup is for Microsoft SQL Server. Thankfully, the
solution above works for Sybase as well.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация