Using SQL2K I have an inbound Date Param @FiscalYear and
it is a char(4)
I want to use it in a Variable called Date Range
Previously the code was written for use in Dynamic SQL so
the whole things was written in a String context.
What I am having trouble getting the correct syntax for
the correct way to define the Date range for "Normal" SQL
and how to use it in the code.
Here's the Code:
declare @FiscalYear char(4)
declare @FiscalYear2 char(4)
select @FiscalYear2 = @FiscalYear - 1
declare @DateRange varchar(150)
THE OLD WAY To Declare a Date Range USING Dynamic SQL
select @DateRange = "BETWEEN CONVERT(DATETIME, '" +
@FiscalYear2 + "-10-01 12:00:00 AM', 102) AND CONVERT
(DATETIME, '" + @FiscalYear + "-09-30 11:59:59 PM', 102))"
Old Way in Body of Code
AND (StatusDate " + @DateRange + "
New Way NOT using Dynamic SQL ?
Define Date Range:
Use in standard Code ?
USE Variable Date Range in Standard Code??
AND (StatusDate <use Variable here>
I hope this makes sense. I have the basics but just not
the fine tuned syntax.
Thanks Beforehand
AJACODE
it is a char(4)
I want to use it in a Variable called Date Range
Previously the code was written for use in Dynamic SQL so
the whole things was written in a String context.
What I am having trouble getting the correct syntax for
the correct way to define the Date range for "Normal" SQL
and how to use it in the code.
Here's the Code:
declare @FiscalYear char(4)
declare @FiscalYear2 char(4)
select @FiscalYear2 = @FiscalYear - 1
declare @DateRange varchar(150)
THE OLD WAY To Declare a Date Range USING Dynamic SQL
select @DateRange = "BETWEEN CONVERT(DATETIME, '" +
@FiscalYear2 + "-10-01 12:00:00 AM', 102) AND CONVERT
(DATETIME, '" + @FiscalYear + "-09-30 11:59:59 PM', 102))"
Old Way in Body of Code
AND (StatusDate " + @DateRange + "
New Way NOT using Dynamic SQL ?
Define Date Range:
Use in standard Code ?
USE Variable Date Range in Standard Code??
AND (StatusDate <use Variable here>
I hope this makes sense. I have the basics but just not
the fine tuned syntax.
Thanks Beforehand
AJACODE