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.
Author |
Topic |
1sabine8
Posting Yak Master
130 Posts |
Posted - 2009-07-02 : 09:29:05
|
Hi,I need to build a report with 2 parameters: month and yearThen i will get the data where the dates are included in the chosen month and year.How is it feasible?Thanks in advance |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-07-02 : 09:41:32
|
[code]DECLARE @Year SMALLINT, @Month TINYINTSELECT @Year = 2008, @Month = 2DECLARE @FromDate DATETIME, @ToDate DATETIMESELECT @FromDate = DATEADD(MONTH, 12 * @Year - 22801 + @Month, 0), @ToDate = DATEADD(MONTH, 12 * @Year - 22800 + @Month, 0)SELECT *FROM Table1WHERE Col1 >= @FromDate AND Col1 < @ToDate[/code] Microsoft SQL Server MVPN 56°04'39.26"E 12°55'05.63" |
|
|
|
|
|