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
 New to SQL Server Programming
 Fetch data between Start and End Dates dynamically

Author  Topic 

rajesh.4334
Starting Member

1 Post

Posted - 2008-06-24 : 13:57:19
The below is a Part of the table structure.

offeringid offeringname RequestDatetime
------------------------------------------------------


10010 Network 6/24/2008 9:05:08 AM
10010 Network 6/24/2008 9:05:11 AM
10010 Network 6/14/2008 9:05:12 AM
10010 Network 6/20/2008 9:05:13 AM
10020 Plasma 6/14/2008 9:05:41 AM
10020 Plasma 6/24/2008 9:05:45 AM
10030 StaffMonitor 6/14/2008 9:06:08 AM
10030 StaffMonitor 6/20/2008 9:06:09 AM
10030 StaffMonitor 6/24/2008 9:06:10 AM
10040 Firmware 6/24/2008 9:06:32 AM
10050 Internet 6/22/2008 9:06:56 AM

Now, when I am running this below query,

select count (offeringid) as "Individual Service Requested", offeringname from RequestTrack where RequestDatetime between '6/1/2008' and '6/25/2008' group by offeringname


I am getting the result like this (result from complete table)...

2 Firmware
12 Internet
7 Network
4 Plasma
5 StaffMonitor

Now, You can see that in the above query the Dates (periods) are hardcoded.But, how can I get the Similar result with the Dynamic variables(StartDate and EndDate) which will be entered from an applications frontend to generate a report)

Please provide your inputs in this concern

Thanks and Regards,
Rajesh...





madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-24 : 14:00:30
Use variables of DATETIME datatype

select count (offeringid) as [Individual Service Requested], offeringname from RequestTrack where RequestDatetime between @start_date and @end_date group by offeringname


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -