>Hi All,
>
>I have to query a SQL table and return all the records based on the datetime field. Given 4 variables that represents starting year, month and ending year,month:
>
>lnYrFrom = 2005
>lnMthFrom = 1
>
>lnYrTo = 2005
>lnMthTo = 3
>
>how can I write a SQL query that will returns all the records within the specified date range?
>
>I appreciate any suggestions,
>Daniel M.
I am not big SQL master but just a suggestion
dtDateFrom = CAST(COVERT(char (4), lnYrFrom)+'0'+CONVERT(char (1), lnMthFrom)+'01000000' as DateTime)
dtDateTo = CAST(COVERT(char (4), lnYrTo) +'0'+CONVERT(char (1), lnMthTo) +'31235959' as DateTime)
SELECT ... WHERE DateField BETWEEN dtDateFrom AND dtDateTo
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.