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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DATE as parameter

Author  Topic 

Nil35
Starting Member

20 Posts

Posted - 2013-09-25 : 16:49:05

Hi Friends
I am looking for something usning 2008R2


DECLARE @CLASS_DATE DATE
SET @CLASS_DATE = '6/%/2013'
SELECT @CLASS_DATE

I 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_DATE
2013-02-28
2013-03-31
2013-04-30
2013-05-08
2013-06-01
2013-07-03


Thank You

Nil

nil

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-09-25 : 21:55:31
like this?

DECLARE @CLASS_DATE DATE

SET @CLASS_DATE = '6/11/2013'

SELECT LEFT(CONVERT(VARCHAR, @CLASS_DATE, 112), 6)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-09-26 : 02:51:13
[code]-- User supplied parameter
DECLARE @ReportDateParameter DATE = '6/12/2013'; -- Any date in wanted month is ok!

-- Prepare sample data
DECLARE @Sample TABLE
(
ClassDate DATE NOT NULL
);

-- Populate sample data
INSERT @Sample
(
ClassDate
)
VALUES ('20130228'),
('20130331'),
('20130430'),
('20130508'),
('20130601'),
('20130703');

-- Initialize interval calculation
DECLARE @FromDate DATE = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', @ReportDateParameter), '19000101'),
@ToDate DATE = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', @ReportDateParameter), '19000201');

-- Return the data
SELECT ClassDate
FROM @Sample
WHERE ClassDate >= @FromDate
AND ClassDate < @ToDate;[/code]


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -