Click here to Skip to main content
15,899,314 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL QUERY Pin
i.j.russell3-Apr-13 21:36
i.j.russell3-Apr-13 21:36 
GeneralRe: SQL QUERY Pin
girijeshkumar3-Apr-13 23:05
girijeshkumar3-Apr-13 23:05 
GeneralRe: SQL QUERY Pin
i.j.russell4-Apr-13 2:07
i.j.russell4-Apr-13 2:07 
AnswerRe: SQL QUERY Pin
Bernhard Hiller3-Apr-13 21:38
Bernhard Hiller3-Apr-13 21:38 
GeneralRe: SQL QUERY Pin
girijeshkumar3-Apr-13 23:07
girijeshkumar3-Apr-13 23:07 
AnswerRe: SQL QUERY Pin
ritesh.gupta55553-Apr-13 22:28
ritesh.gupta55553-Apr-13 22:28 
GeneralRe: SQL QUERY Pin
girijeshkumar3-Apr-13 22:58
girijeshkumar3-Apr-13 22:58 
GeneralRe: SQL QUERY Pin
ritesh.gupta555525-Jun-13 2:55
ritesh.gupta555525-Jun-13 2:55 
QuestionSQL QUERY Pin
Dobrobit2-Apr-13 8:41
Dobrobit2-Apr-13 8:41 
AnswerRe: SQL QUERY Pin
David Mujica2-Apr-13 9:12
David Mujica2-Apr-13 9:12 
AnswerRe: SQL QUERY Pin
Corporal Agarn2-Apr-13 9:17
professionalCorporal Agarn2-Apr-13 9:17 
AnswerRe: SQL QUERY Pin
Richard Deeming2-Apr-13 10:40
mveRichard Deeming2-Apr-13 10:40 
Questionwhen use of index on view instead of table Pin
mhd.sbt2-Apr-13 7:01
mhd.sbt2-Apr-13 7:01 
AnswerRe: when use of index on view instead of table Pin
R. Giskard Reventlov2-Apr-13 7:11
R. Giskard Reventlov2-Apr-13 7:11 
Questionbenefit of cluster index on view in sql 2008 r2 Pin
mhd.sbt2-Apr-13 1:45
mhd.sbt2-Apr-13 1:45 
AnswerRe: benefit of cluster index on view in sql 2008 r2 Pin
Simon_Whale2-Apr-13 1:56
Simon_Whale2-Apr-13 1:56 
GeneralRe: benefit of cluster index on view in sql 2008 r2 Pin
mhd.sbt2-Apr-13 5:16
mhd.sbt2-Apr-13 5:16 
QuestionDifference in Sum(column) between two tables Pin
Richard.Berry1001-Apr-13 3:45
Richard.Berry1001-Apr-13 3:45 
AnswerRe: Difference in Sum(column) between two tables Pin
David Mujica1-Apr-13 4:12
David Mujica1-Apr-13 4:12 
GeneralRe: Difference in Sum(column) between two tables Pin
Richard.Berry1004-Apr-13 8:05
Richard.Berry1004-Apr-13 8:05 
AnswerRe: Difference in Sum(column) between two tables Pin
Jörgen Andersson1-Apr-13 8:21
professionalJörgen Andersson1-Apr-13 8:21 
GeneralRe: Difference in Sum(column) between two tables Pin
Richard.Berry1004-Apr-13 7:34
Richard.Berry1004-Apr-13 7:34 
Awesome! Thanks Jörgen

SQL
SELECT tStk.WH + ' - ' + tStk.StockCode as [WP], sum(tStk.Qty) as [StkTot],  IIF(tHst.HstTot is null,0, tHst.HstTot) AS [HstTot], sum(tStk.Qty)  -  IIF(tHst.HstTot is null,0, tHst.HstTot) AS [Difference]
FROM stock_qty AS tStk
LEFT JOIN (SELECT stock_history.Location + ' - ' + stock_history.StockCode AS [WP], sum(stock_history.Qty) as [HstTot]
FROM stock_history 
GROUP BY stock_history.Location+ ' - ' + stock_history.StockCode) AS [tHst] ON  tStk.WH + ' - ' + tStk.StockCode =tHst.WP
GROUP BY tStk.WH+ ' - ' + tStk.StockCode ,  tHst.HstTot
HAVING sum(tStk.Qty) <>tHst.HstTot


I see that:

Aggregate functions can be used as expressions only in the following:
The select list of a SELECT statement (either a subquery or an outer query).
A COMPUTE or COMPUTE BY clause.
A HAVING clause.
Question2pc in SQL server Pin
Soiraian31-Mar-13 6:21
Soiraian31-Mar-13 6:21 
AnswerRe: 2pc in SQL server Pin
RedDk31-Mar-13 7:44
RedDk31-Mar-13 7:44 
QuestionViews vs Tables Pin
Eric Whitmore29-Mar-13 4:50
Eric Whitmore29-Mar-13 4:50 

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.