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
 multiple values for date

Author  Topic 

cajay
Starting Member

2 Posts

Posted - 2012-08-10 : 16:18:47
Can someone please help me refine this query so that I am able to parse multiple date for following condition "'2010-01-15' between e.enr_startDate and e.enr_endDate". how can we parametrize the query.

select distinct
m.mem_id
, CASE m.gndr_Code
WHEN 1 then 'Male'
WHEN 2 then 'Female'
ELSE 'Unknown'
END as GenderDescription
, DATEDIFF(yy,m.mem_Birthday,@enrollmentDate)
from
dbo.tbMember m
inner join dbo.vw_Enrollment e on
m.mem_id=e.mem_id
AND '2010-01-15' between e.enr_startDate and e.enr_endDate

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-10 : 16:21:04
declare a parameter by name @Date and use like

AND @Date >= e.enr_startDate
and @Date< e.enr_endDate +1

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

cajay
Starting Member

2 Posts

Posted - 2012-08-10 : 16:41:18
can i give 3 different dates in the query at once and get results for all of it.similar to the following
when date in('20120101','20120201','20120301')
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-08-10 : 16:44:40
What you have provided us so far doesn't make much sense. It'll be more helpful to supply examples with data and expected output. Please review the following links for how to refine your question.
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-10 : 16:58:33
quote:
Originally posted by cajay

can i give 3 different dates in the query at once and get results for all of it.similar to the following
when date in('20120101','20120201','20120301')


are you looking for exact matches or range?
previous question was on a range so not sure what exactly you're after

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -