Click here to Skip to main content
15,947,523 members
Home / Discussions / Database
   

Database

 
AnswerRe: DSN Pin
cdpsource11-Mar-14 2:14
cdpsource11-Mar-14 2:14 
AnswerRe: DSN Pin
Mycroft Holmes11-Mar-14 2:25
professionalMycroft Holmes11-Mar-14 2:25 
QuestionHo to avoid Not In & In clause in my query Pin
member002611-Mar-14 0:43
member002611-Mar-14 0:43 
AnswerRe: Ho to avoid Not In & In clause in my query Pin
Bernhard Hiller11-Mar-14 1:04
Bernhard Hiller11-Mar-14 1:04 
GeneralRe: Ho to avoid Not In & In clause in my query Pin
member002611-Mar-14 18:08
member002611-Mar-14 18:08 
AnswerRe: Ho to avoid Not In & In clause in my query Pin
thatraja11-Mar-14 2:07
professionalthatraja11-Mar-14 2:07 
AnswerRe: Ho to avoid Not In & In clause in my query Pin
GuyThiebaut11-Mar-14 3:54
professionalGuyThiebaut11-Mar-14 3:54 
QuestionAdding Sales Totals from multiple tables Pin
jkirkerx9-Mar-14 10:54
professionaljkirkerx9-Mar-14 10:54 
I'm trying to write better TSQL to reduce the amount of functions I have to do things.

Here I'm trying to add the total amount of sales from a column called GrandTotal from multiple tables
into a single result. First I'm not sure if this is even possible to do, but I think it can be done.

I've come this far, but I get 2 results returned. I'm just trying to consolidate them into one.

I tried SELECT SUM(TotalAmount) as the wrapper, but I get a syntax error
I tried UNION ALL without the )( around around it, but I get an error on the last )

The tables are identical in columns

DECLARE @StartDate AS Date;
DECLARE @StopDate AS Date;
SET @StartDate = CONVERT(CHAR(10),GETDATE(),101);
SET @StopDate = CONVERT(CHAR(10),DATEADD(d,1, GETDATE()),101);

SELECT
(
    SELECT SUM(GrandTotal)
    FROM CompletedOrdersHistory
    WHERE OrderStatus='COMPLETED'
    AND OrderDate >= @StartDate
    AND OrderDate < @StopDate        
)
    UNION ALL
(
    SELECT SUM(GrandTotal)
    FROM CompletedOrders
    WHERE OrderStatus='COMPLETED'	
    AND OrderDate >= @StartDate
    AND OrderDate < @StopDate
)

AnswerRe: Adding Sales Totals from multiple tables Pin
Mycroft Holmes9-Mar-14 14:16
professionalMycroft Holmes9-Mar-14 14:16 
GeneralRe: Adding Sales Totals from multiple tables Pin
jkirkerx9-Mar-14 17:44
professionaljkirkerx9-Mar-14 17:44 
AnswerRe: Adding Sales Totals from multiple tables Pin
Jörgen Andersson9-Mar-14 22:01
professionalJörgen Andersson9-Mar-14 22:01 
GeneralRe: Adding Sales Totals from multiple tables Pin
jkirkerx10-Mar-14 6:26
professionaljkirkerx10-Mar-14 6:26 
GeneralRe: Adding Sales Totals from multiple tables Pin
Jörgen Andersson10-Mar-14 8:35
professionalJörgen Andersson10-Mar-14 8:35 
QuestionHow to prevent or allow a insert trigger ? Pin
ngoloi9-Mar-14 6:15
ngoloi9-Mar-14 6:15 
AnswerRe: How to prevent or allow a insert trigger ? Pin
Mycroft Holmes9-Mar-14 13:09
professionalMycroft Holmes9-Mar-14 13:09 
GeneralRe: How to prevent or allow a insert trigger ? Pin
ngoloi9-Mar-14 18:02
ngoloi9-Mar-14 18:02 
AnswerRe: How to prevent or allow a insert trigger ? Pin
GuyThiebaut9-Mar-14 22:37
professionalGuyThiebaut9-Mar-14 22:37 
GeneralRe: How to prevent or allow a insert trigger ? Pin
ngoloi10-Mar-14 4:28
ngoloi10-Mar-14 4:28 
GeneralRe: How to prevent or allow a insert trigger ? Pin
GuyThiebaut10-Mar-14 4:52
professionalGuyThiebaut10-Mar-14 4:52 
QuestionSql Server Express: Testing sql-commands Pin
Frygreen9-Mar-14 3:03
Frygreen9-Mar-14 3:03 
AnswerRe: Sql Server Express: Testing sql-commands Pin
Richard MacCutchan9-Mar-14 3:33
mveRichard MacCutchan9-Mar-14 3:33 
AnswerRe: Sql Server Express: Testing sql-commands Pin
Jörgen Andersson9-Mar-14 7:42
professionalJörgen Andersson9-Mar-14 7:42 
AnswerRe: Sql Server Express: Testing sql-commands Pin
Mycroft Holmes9-Mar-14 13:05
professionalMycroft Holmes9-Mar-14 13:05 
AnswerRe: Sql Server Express: Testing sql-commands Pin
Richard Deeming10-Mar-14 2:49
mveRichard Deeming10-Mar-14 2:49 
GeneralRe: Sql Server Express: Testing sql-commands Pin
Frygreen10-Mar-14 7:40
Frygreen10-Mar-14 7:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.