Click here to Skip to main content
15,888,454 members
Home / Discussions / Database
   

Database

 
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 
AnswerRe: Views vs Tables Pin
PIEBALDconsult29-Mar-13 5:37
mvePIEBALDconsult29-Mar-13 5:37 
GeneralRe: Views vs Tables Pin
Eric Whitmore29-Mar-13 5:47
Eric Whitmore29-Mar-13 5:47 
GeneralRe: Views vs Tables Pin
PIEBALDconsult29-Mar-13 6:21
mvePIEBALDconsult29-Mar-13 6:21 
GeneralRe: Views vs Tables Pin
GuyThiebaut30-Mar-13 5:29
professionalGuyThiebaut30-Mar-13 5:29 
GeneralRe: Views vs Tables Pin
PIEBALDconsult30-Mar-13 5:51
mvePIEBALDconsult30-Mar-13 5:51 
GeneralRe: Views vs Tables Pin
GuyThiebaut30-Mar-13 5:57
professionalGuyThiebaut30-Mar-13 5:57 
GeneralRe: Views vs Tables Pin
jschell30-Mar-13 12:46
jschell30-Mar-13 12:46 
GeneralRe: Views vs Tables Pin
GuyThiebaut30-Mar-13 20:37
professionalGuyThiebaut30-Mar-13 20:37 
GeneralRe: Views vs Tables Pin
jschell31-Mar-13 11:31
jschell31-Mar-13 11:31 
GeneralRe: Views vs Tables Pin
jschell30-Mar-13 12:45
jschell30-Mar-13 12:45 
AnswerRe: Views vs Tables Pin
Corporal Agarn29-Mar-13 7:43
professionalCorporal Agarn29-Mar-13 7:43 
AnswerRe: Views vs Tables Pin
jschell29-Mar-13 11:00
jschell29-Mar-13 11:00 
GeneralRe: Views vs Tables Pin
PIEBALDconsult29-Mar-13 15:38
mvePIEBALDconsult29-Mar-13 15:38 
AnswerRe: Views vs Tables Pin
Mycroft Holmes29-Mar-13 13:19
professionalMycroft Holmes29-Mar-13 13:19 

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.