Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Question on Parameter
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kevie
Starting Member

6 Posts

Posted - 01/23/2014 :  17:12:03  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 01/24/2014 :  01:00:48  Show Profile  Reply with Quote
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 - 01/24/2014 :  11:07:36  Show Profile  Reply with Quote
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

USA
819 Posts

Posted - 01/24/2014 :  17:42:45  Show Profile  Reply with Quote
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

India
22864 Posts

Posted - 01/27/2014 :  02:01:39  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
52326 Posts

Posted - 01/27/2014 :  07:39:48  Show Profile  Reply with Quote
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
  Previous Topic Topic Next 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