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
 Script Library
 Selecting dynamic date range

Author  Topic 

kishoremcp
Starting Member

41 Posts

Posted - 2013-10-02 : 03:36:57
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

22864 Posts

Posted - 2013-10-03 : 08:40:37
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
Go to Top of Page
   

- Advertisement -