SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Outer Join problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kyssling
Starting Member

1 Posts

Posted - 04/17/2014 :  15:16:38  Show Profile  Reply with Quote
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 ?

Edited by - kyssling on 04/17/2014 15:22:57

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 04/17/2014 :  16:04:01  Show Profile  Reply with Quote
>>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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000