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
 Outer Join problem

Author  Topic 

kyssling
Starting Member

1 Post

Posted - 2014-04-17 : 15:16:38
Hi please I need help with following problem :
tableone :
contract
100001
tabletwo :
payments, reimbursement
10000101,100
10000102,200
10000103,500

now i need sum for every contract LEFT(payments,6) ... i use next
(i use next left joins on other tables without problem in this SELECT) :
LEFT OUTER JOIN
(SELECT payments, LEFT(LTRIM(STR(Payments)), 6) AS PayContract, SUM(reimbursement) AS ContractSum
FROM dbo.tabletwo
GROUP BY Payments) Uhrady ON LEFT(LTRIM(STR(Uhrady.Payment)), 6) = LTRIM(STR(tableone.Contract)

Output:
for every payments ... thats bad i need some as

LEFT OUTER JOIN
(SELECT payments, LEFT(LTRIM(STR(Payments)), 6) AS PayContract, SUM(reimbursement) AS ContractSum
FROM dbo.tabletwo
GROUP BY LEFT(LTRIM(STR(Uhrady.Payment)), 6)) Uhrady ON LEFT(LTRIM(STR(Uhrady.Payment)), 6) = LTRIM(STR(tableone.Contract)

but this is error Payment invalid ....

Anybody can me help please ?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-04-17 : 16:04:01
>>Anybody can me help please ?
Maybe but I can't tell what the question is.

If you are getting an error then post the entire actual statement you are running and the exact error message text. If you want to provide tables with sample data that is great but you need to post executable DDL/DML. ie: working CREATE TABLE statements and actual INSERT VALUES statements with your sample data. Finally the expected results based on your sample data.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -