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
 Script Library
 Selecting dynamic date range
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kishoremcp
Starting Member

India
39 Posts

Posted - 10/02/2013 :  03:36:57  Show Profile  Reply with Quote
Hi,

I have an sql query in Excel Existing connections through which i am able to pull the data. I am giving the required date range manually in sql query and pulling the data.

Is there a possibility so that I can give the start date and the end date in excel. (Ex: Sheet1!A1 has the start date and Sheet1!B1 has the end date).

Now the sql macro should take the input of start and end date from excel and pull the date.

Please help me how to do that.

Below is the sql query with me..

select Naming, Date, Fields, Numbers
from HJDU
where Fields in (23, 25, 27)
and
Numbers in (1,2,3)
and
Date >=2013-09-01 and Date <=2013-09-30
order by Date


Here what i want dynamically is to pull the previous month data.

Thanks in advance.

Regards
Kishore

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 10/03/2013 :  08:40:37  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
select Naming, Date, Fields, Numbers
from HJDU
where Fields in (23, 25, 27)
and
Numbers in (1,2,3)
and
Date >=dateadd(month,datediff(month,0,getdate())-1,0) and Date <dateadd(month,datediff(month,0,getdate()),0)
order by Date


Madhivanan

Failing to plan is Planning to fail

Edited by - madhivanan on 10/03/2013 08:41:43
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.06 seconds. Powered By: Snitz Forums 2000