Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please see the following SQL query and its result :
SQL
Select tbl.NetPayable,tbl.OTAmount from (Select sum(cast(S.NetPayable as decimal))as NetPayable,sum (cast(S.OTAmount as decimal)) as OTAmount From tblLocationWiseSalaryRecord S
where month(S.SalarySTDT) = '9' and YEAR(S.SalarySTDT)='2013' and S.CompanyCode='CMP-001' and S.ETCode='ETC-001'and S.DeptCode='DPT-036')as tbl

Union all
(Select sum(cast(S.NetPayable as decimal))as NetPayable,sum (cast(S.OTAmount as decimal)) as OTAmount From tblLocationWiseSalaryRecord S
where month(S.SalarySTDT) = '9' and YEAR(S.SalarySTDT)='2013' and S.CompanyCode='CMP-002' and S.ETCode='ETC-001'and S.DeptCode='DPT-036')



NetPayable  OTAmount
207055       4073
201573       4610


I want the result like as follows :
NetPayable       OTAmount         NetPayable     OTAmount
207055           4073             201573         4610  

How can I do this. Please help me.
Posted
Updated 25-Nov-13 22:43pm
v3
Comments
Maciej Los 26-Nov-13 6:09am    
Why?

You can try this. I have corrected the error

SQL
CREATE TABLE #OutTable( NetPayable1 DECIMAL, OTAmount1 DECIMAL, NetPayable2 DECIMAL, OTAmount2 DECIMAL)
DECLARE @NetPayable2 AS DECIMAL
DECLARE @OTAmount2 AS DECIMAL

INSERT INTO #OutTable (NetPayable1, OTAmount1)
Select tbl.NetPayable,tbl.OTAmount from (Select sum(cast(S.NetPayable as decimal))as NetPayable,sum (cast(S.OTAmount as decimal)) as OTAmount From tblLocationWiseSalaryRecord S
where month(S.SalarySTDT) = '9' and YEAR(S.SalarySTDT)='2013' and S.CompanyCode='CMP-001' and S.ETCode='ETC-001'and S.DeptCode='DPT-036')as tbl



Select @NetPayable2 = sum(cast(S.NetPayable as decimal)), @OTAmount2 = sum (cast(S.OTAmount as decimal)) From tblLocationWiseSalaryRecord S
where month(S.SalarySTDT) = '9' and YEAR(S.SalarySTDT)='2013' and S.CompanyCode='CMP-002' and S.ETCode='ETC-001'and S.DeptCode='DPT-036'
UPDATE #OutTable SET NetPayable2 = @NetPayable2, OTAmount2 = @OTAmount2

SELECT * FROM #OutTable
DROP TABLE #OutTable
 
Share this answer
 
v2
Comments
Sumon562 26-Nov-13 6:40am    
Thanks Mr. obhijitghosh for your kind response. This query arises an error. The error is in the line of
'Select @NetPayable2 = sum(cast(S.NetPayable as decimal)) as NetPayable, @OTAmount2 = sum (cast(S.OTAmount'
Incorrect syntex near the keyword as.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900