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.
Author |
Topic |
anaze
Starting Member
6 Posts |
Posted - 2013-09-15 : 04:44:18
|
-- Create TableCREATE 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]GOSET ANSI_PADDING OFFGO--INSERT DATAINSERT 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 bri1 100 200 300 4002 500 600 700 800--I WANT RESULT IS : mandiri1 600mandiri2 800bni 1000bri 1200assumpsion column is dinamically,...please help me, about pivot or others way..Thanks alot before. |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-09-16 : 02:53:12
|
DECLARE @x TABLE ( customer_code varchar(max), Value decimal(10,2), Value1 decimal(10,2));INSERT @x SELECT 'mandiri1',100,500UNION ALL SELECT 'mandiri2',200,600UNION ALL SELECT 'bni',300,700UNION ALL SELECT 'bri',400,800select x.Customer_Code,(x.Value + x.Value1) as Value from @x as xinner join fa_wcb_rpt_bak as pon x.value = p.bnior x.value = p.brior x.value = p.mandiri1or 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_codeveeranjaneyulu |
|
|
anaze
Starting Member
6 Posts |
Posted - 2013-09-25 : 11:07:03
|
Thanks you Mr. veeranjaneyulu |
|
|
|
|
|
|
|