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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Two SQL Statmens to one; Group

Author  Topic 

fischer_andreas
Starting Member

1 Post

Posted - 2011-10-20 : 16:09:21
Hello Team,

I have a SQL Script:

use db_xy
SELECT KOSTKKA.KKa_Nr AS KA, KOSTKKA.KKa_Bez AS KABEZ, right(KOSTKKS.KKs_Nr,4) AS KST, KOSTKKS.KKs_Bez AS KSTBEZ, MONTH(KOSTKBU.KBu_BelDat)
AS Monat, YEAR(KOSTKBU.KBu_BelDat) AS Jahr, KOSTKBU.KBu_BelDat AS BelDat, KOSTKBU.KBu_Text AS BuchTXT,
(case
When KOSTKBU.KBU_Haben = -1 then KOSTKBU.KBU_Euro * (-1)
Else KOSTKBU.KBU_Euro
END
) AS Betrag
FROM KOSTKBU INNER JOIN
KOSTKKS ON KOSTKBU.KKs_IdSoll = KOSTKKS.KKs_Id INNER JOIN
KOSTKKA ON KOSTKBU.KKa_IdSoll = KOSTKKA.KKa_Id
WHERE (KOSTKKS.KKk_id=11)
order by KA

The same script is with "where ...kkk_id=12)"
--> So. With id=11 and id=12.

These are financial datas with two cost-circles (is this the right expression.....?)

Every account record is with date/money/text/cost1/cost2
Cost1 is kkk_id=11 and Cost2 is kkk_id=12

every statement works fine within itself. But I want a integrated statement:

e.G.:
Kost-Art Kostenstelle Betrag
4000 100 500

whithin:
4000 101 200
4000 102 200
4000 103 100

sum is 500.....

The first part is from ...kkk_id =11
The second part is from ...kkk_id = 12

sort criteria is "KA", in this case 4000.

How can I make this?
It should be a Group By oder so? I can not program it.

Thank you
Andreas

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2011-10-20 : 18:34:49
WHERE (KOSTKKS.KKk_id in (11, 12) ???


=======================================
Faced with the choice between changing one's mind and proving that there is no need to do so, almost everyone gets busy on the proof. -John Kenneth Galbraith
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-21 : 00:41:22
you want costs in different columns or consolidated into same column?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -