Click here to Skip to main content
15,886,110 members
Home / Discussions / Database
   

Database

 
GeneralRe: can someone find the error please Pin
Jörgen Andersson13-Nov-11 20:49
professionalJörgen Andersson13-Nov-11 20:49 
GeneralRe: can someone find the error please Pin
PIEBALDconsult14-Nov-11 1:40
mvePIEBALDconsult14-Nov-11 1:40 
AnswerRe: can someone find the error please Pin
Jörgen Andersson13-Nov-11 8:17
professionalJörgen Andersson13-Nov-11 8:17 
QuestionHow to open LDF file of SQL2000 Pin
Cold_Fearing_Bird10-Nov-11 18:52
Cold_Fearing_Bird10-Nov-11 18:52 
AnswerRe: How to open LDF file of SQL2000 Pin
Corporal Agarn11-Nov-11 1:23
professionalCorporal Agarn11-Nov-11 1:23 
AnswerRe: How to open LDF file of SQL2000 Pin
SilimSayo14-Nov-11 15:58
SilimSayo14-Nov-11 15:58 
QuestionData from multiple tables Pin
Manmohan2910-Nov-11 7:25
Manmohan2910-Nov-11 7:25 
AnswerRe: Data from multiple tables Pin
loyal ginger10-Nov-11 8:52
loyal ginger10-Nov-11 8:52 
You can divide this task into three parts. The first part uses inner join to find the records from both tables with common date/time. The second part deals with the case that date/time only appears in the first table. The third part deals with the case that date/time only appears in the second table. The result is a union of the above three queries.

To show you what I mean in a cleaner example, let's suppose the first table is called "Table1" with the following two fields: a1 and a2 (corresponding to your "Sales" table's SaleDateTime and Cost columns), and the second table is called "Table2" with the following two fields: a1 and a2 (corresponding to your "Purchase" table's PurchaseDateTime and Cost columns). The following query should give you what you wanted.

SELECT a.a1, sum(a.aa2), sum(b.aa2)
FROM (SELECT a1, sum(a2) as aa2 FROM Table1 GROUP BY a1) as a,
(SELECT a1, sum(a2) as aa2 FROM Table2 GROUP BY a1) as b
WHERE (a.a1=b.a1)
GROUP BY a.a1;

UNION

SELECT a1, sum(a2), 0
FROM Table1
WHERE a1 not in (SELECT a1 FROM Table2)
GROUP BY a1

UNION

SELECT a1, 0, sum(a2)
FROM Table2
WHERE a1 not in (SELECT a1 FROM Table1)
GROUP BY a1

GeneralRe: Data from multiple tables Pin
SilimSayo10-Nov-11 9:10
SilimSayo10-Nov-11 9:10 
GeneralRe: Data from multiple tables Pin
Manmohan2910-Nov-11 19:16
Manmohan2910-Nov-11 19:16 
GeneralRe: Data from multiple tables Pin
SilimSayo11-Nov-11 7:11
SilimSayo11-Nov-11 7:11 
GeneralRe: Data from multiple tables Pin
Manmohan2911-Nov-11 7:33
Manmohan2911-Nov-11 7:33 
Questiondatabase deployment Pin
murali_utr10-Nov-11 4:08
murali_utr10-Nov-11 4:08 
AnswerRe: database deployment Pin
Corporal Agarn10-Nov-11 4:26
professionalCorporal Agarn10-Nov-11 4:26 
AnswerRe: database deployment Pin
jschell10-Nov-11 8:56
jschell10-Nov-11 8:56 
QuestionMaster.dbo.xp_fileexist in sql Pin
vanikanc10-Nov-11 3:26
vanikanc10-Nov-11 3:26 
AnswerRe: Master.dbo.xp_fileexist in sql Pin
Eddy Vluggen10-Nov-11 10:20
professionalEddy Vluggen10-Nov-11 10:20 
QuestionHeterogeneous Database; What will you do? Pin
AbrahamMOKDAD9-Nov-11 18:58
AbrahamMOKDAD9-Nov-11 18:58 
AnswerRe: Heterogeneous Database; What will you do? Pin
Eddy Vluggen10-Nov-11 10:51
professionalEddy Vluggen10-Nov-11 10:51 
AnswerRe: Heterogeneous Database; What will you do? Pin
Mycroft Holmes13-Nov-11 6:20
professionalMycroft Holmes13-Nov-11 6:20 
AnswerRe: Heterogeneous Database; What will you do? Pin
SilimSayo14-Nov-11 15:35
SilimSayo14-Nov-11 15:35 
Questionstring truncation Pin
Luc Pattyn9-Nov-11 10:37
sitebuilderLuc Pattyn9-Nov-11 10:37 
AnswerRe: string truncation Pin
jschell9-Nov-11 11:21
jschell9-Nov-11 11:21 
GeneralRe: string truncation Pin
Luc Pattyn9-Nov-11 11:24
sitebuilderLuc Pattyn9-Nov-11 11:24 
GeneralRe: string truncation Pin
SilimSayo9-Nov-11 14:59
SilimSayo9-Nov-11 14:59 

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.