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
 Filter between two dates

Author  Topic 

josef
Starting Member

15 Posts

Posted - 2013-08-10 : 01:07:56
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

30421 Posts

Posted - 2013-08-10 : 03:05:20
[code]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;[/code]


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

josef
Starting Member

15 Posts

Posted - 2013-08-14 : 03:08:36
Thanks for your reply. I got the logic ,I can solve the problem .
Go to Top of Page
   

- Advertisement -