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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 need help,.. how make column dinamically to rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

anaze
Starting Member

Indonesia
6 Posts

Posted - 09/15/2013 :  04:44:18  Show Profile  Reply with Quote
-- Create Table
CREATE TABLE [dbo].[fa_wcb_rpt_bak](
[urut] [int] IDENTITY(1,1) NOT NULL,
[mandiri1] [decimal](18, 0) NULL,
[mandiri2] [decimal](18, 0) NULL,
[bni] [decimal](18, 0) NULL,
[bri] [decimal](18, 0) NULL,
CONSTRAINT [PK_fa_wcb_rpt_bak] PRIMARY KEY CLUSTERED
(
[urut] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

--INSERT DATA
INSERT INTO fa_wcb_rpt_bak VALUES (100,200,300,400)
INSERT INTO fa_wcb_rpt_bak VALUES (500,600,700,800)

--VIEW DATA
select * from fa_wcb_rpt_bak
urut mandiri1 mandiri2 bni bri
1 100 200 300 400
2 500 600 700 800

--I WANT RESULT IS :

mandiri1 600
mandiri2 800
bni 1000
bri 1200

assumpsion column is dinamically,...
please help me, about pivot or others way..
Thanks alot before.

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
165 Posts

Posted - 09/16/2013 :  02:53:12  Show Profile  Reply with Quote
DECLARE @x TABLE
(
customer_code varchar(max),
Value decimal(10,2),
Value1 decimal(10,2)
);

INSERT @x SELECT 'mandiri1',100,500
UNION ALL SELECT 'mandiri2',200,600
UNION ALL SELECT 'bni',300,700
UNION ALL SELECT 'bri',400,800

select x.Customer_Code,(x.Value + x.Value1) as Value
from @x as x
inner join fa_wcb_rpt_bak as p
on x.value = p.bni
or x.value = p.bri
or x.value = p.mandiri1
or x.value = p.mandiri2
--or x.Value1 = p.bni
--or x.Value1 = p.bri
--or x.Value1 = p.mandiri1
--or x.Value1 = p.mandiri2
group by x.Value,x.Value1,x.customer_code


veeranjaneyulu

Edited by - VeeranjaneyuluAnnapureddy on 09/16/2013 03:00:15
Go to Top of Page

anaze
Starting Member

Indonesia
6 Posts

Posted - 09/25/2013 :  11:07:03  Show Profile  Reply with Quote
Thanks you Mr. veeranjaneyulu
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.06 seconds. Powered By: Snitz Forums 2000