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 |
Nil35
Starting Member
20 Posts |
Posted - 2013-09-25 : 16:49:05
|
Hi FriendsI am looking for something usning 2008R2 DECLARE @CLASS_DATE DATE SET @CLASS_DATE = '6/%/2013' SELECT @CLASS_DATEI want to assing @class_date as report parameter and and user will add any date but I just want to take month and year as date.date coloum is shown below Class_DATE2013-02-28 2013-03-31 2013-04-30 2013-05-08 2013-06-01 2013-07-03 Thank YouNilnil |
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2013-09-25 : 21:55:31
|
like this?DECLARE @CLASS_DATE DATESET @CLASS_DATE = '6/11/2013'SELECT LEFT(CONVERT(VARCHAR, @CLASS_DATE, 112), 6) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-26 : 02:51:13
|
[code]-- User supplied parameterDECLARE @ReportDateParameter DATE = '6/12/2013'; -- Any date in wanted month is ok!-- Prepare sample dataDECLARE @Sample TABLE ( ClassDate DATE NOT NULL );-- Populate sample dataINSERT @Sample ( ClassDate )VALUES ('20130228'), ('20130331'), ('20130430'), ('20130508'), ('20130601'), ('20130703');-- Initialize interval calculationDECLARE @FromDate DATE = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', @ReportDateParameter), '19000101'), @ToDate DATE = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', @ReportDateParameter), '19000201');-- Return the dataSELECT ClassDateFROM @SampleWHERE ClassDate >= @FromDate AND ClassDate < @ToDate;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|