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
 New to SQL Server Programming
 Filter between two dates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

josef
Starting Member

USA
15 Posts

Posted - 08/10/2013 :  01:07:56  Show Profile  Reply with Quote
hello friends
help me to write sql query that will filter between two dates (user input in text box1 and text box2) in the bellow sql statement .any bit of info would be helpful
SELECT 'Table1' AS [Table], SUM(a) - SUM(b) AS Result FROM table1  UNION ALL SELECT 'Table2', SUM(a) - SUM(b)  FROM table2   UNION ALL SELECT 'Table3', SUM(a) - SUM(b) FROM table3

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 08/10/2013 :  03:05:20  Show Profile  Visit SwePeso's Homepage  Reply with Quote
DECLARE	@FromDate DATE = {Content from textbox 1},
	@ToDate DATE = {Content from textbox 2};

SELECT	'Table1' AS [Table], 
	SUM(a) - SUM(b) AS Result 
FROM	dbo.Table1
WHERE	MyDateTimeColumn BETWEEN @FromDate AND @ToDate

UNION ALL 

SELECT	'Table2', 
	SUM(a) - SUM(b)  
FROM	dbo.Table2   
WHERE	MyDateTimeColumn BETWEEN @FromDate AND @ToDate

UNION ALL 

SELECT	'Table3', 
	SUM(a) - SUM(b) 
FROM	dbo.Table3
WHERE	MyDateTimeColumn BETWEEN @FromDate AND @ToDate;



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

josef
Starting Member

USA
15 Posts

Posted - 08/14/2013 :  03:08:36  Show Profile  Reply with Quote
Thanks for your reply. I got the logic ,I can solve the problem .
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.05 seconds. Powered By: Snitz Forums 2000