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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Question on Parameter

Author  Topic 

kevie
Starting Member

6 Posts

Posted - 2014-01-23 : 17:12:03
Hello,

I am currently creating a report with a start and end date parameter. What I am trying to achieve is if the date range is set to 1/1/2013 and 12/31/2013, but the client started on 2/1/2013 or ended on 10/1/2013, then I want it to adjust the dates accordingly. Would anyone happen to know how to approach this?

Thank you!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-24 : 01:00:48
sorry didnt get what you meant by adjust dates. do you've two columns in your table for storing the dates?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kevie
Starting Member

6 Posts

Posted - 2014-01-24 : 11:07:36
So let's say that I have a client that started business with me on 2/1/2013 and then terminated on 10/1/2013.

Let's say I run a query and the parameter start date will say 1/1/2013 and the end date will say 12/1/2013.

However, I want it to change it from the 1/1/2013 and 12/1/2013 to 2/1/2013 and 10/1/2013.

Does this help explain it a bit clearer?
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2014-01-24 : 17:42:45
If your date range is 1/1/xxxx through 12/31/xxxx and the company started after your start and ended before your end - it should still show up in your query.

WHERE startDate >= @startDate
AND endDate < dateadd(day, 1, @endDate)

If you are doing something else, more explanation will be needed.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-01-27 : 02:01:39
Also use unambiguous date formats
http://beyondrelational.com/modules/2/blogs/70/posts/10898/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-27 : 07:39:48
quote:
Originally posted by kevie

So let's say that I have a client that started business with me on 2/1/2013 and then terminated on 10/1/2013.

Let's say I run a query and the parameter start date will say 1/1/2013 and the end date will say 12/1/2013.

However, I want it to change it from the 1/1/2013 and 12/1/2013 to 2/1/2013 and 10/1/2013.

Does this help explain it a bit clearer?


hmm...so whatabout other clients with different start and termination date values?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -