Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Selecting dynamic date range


Selecting dynamic date range

Author
Message
kishoremcp
kishoremcp
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 8
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.
MarkusB
MarkusB
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4457 Visits: 4208
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search