Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Selecting dynamic date range Expand / Collapse
Author
Message
Posted Wednesday, October 02, 2013 1:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, October 04, 2013 12:51 AM
Points: 2, Visits: 6
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.
Post #1500676
Posted Wednesday, October 02, 2013 3:26 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Thursday, April 03, 2014 8:27 AM
Points: 4,432, Visits: 4,155
kishoremcp (10/2/2013)
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.


Use the DATE functions. For the previous month this would be:

SELECT Naming, Date, Fields, Numbers
from HJDU
where Fields in (23, 25, 27)
and
Numbers in (1,2,3)
and
WHERE DATE BETWEEN DATEADD(D,-DATEPART(d,GETDATE())+1,DATEADD(M,-1,CAST(GETDATE() as date)))
AND DATEADD(D,-DATEPART(D,getdate()),CAST(GETDATE()as date))


Markus Bohse
Post #1500702
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse