SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DATE as parameter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Nil35
Starting Member

USA
17 Posts

Posted - 09/25/2013 :  16:49:05  Show Profile  Reply with Quote

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

Malaysia
961 Posts

Posted - 09/25/2013 :  21:55:31  Show Profile  Reply with Quote
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

Sweden
30217 Posts

Posted - 09/26/2013 :  02:51:13  Show Profile  Visit SwePeso's Homepage  Reply with Quote
-- 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;



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000