You should re-think the table structure.Is there a reason the Check 'Y" rows are in the same table with the check 'N' rows?declare @Item table (Line int, Code nvarchar(8),Price decimal, [Check] nvarchar(1))INSERT INTO @Item VALUES (1,'001',200 ,'Y')INSERT INTO @Item VALUES (2,'002',300 ,'Y')INSERT INTO @Item VALUES (3,'003',500 ,'Y')INSERT INTO @Item VALUES (4,'004',1000,'N')INSERT INTO @Item VALUES (5,'005',2000,'N')declare @ItemColumns table (Line int, Code nvarchar(8),Price decimal, [Check] nvarchar(1))Insert into @ItemColumnsSelect * From @Item awhere a.[Check] = 'N'--Your math looks to be wrong, I assumed you wanted 200/(200+300+500) not 200/200 then add 300+500Select a.*,b.Price,(b.Price * (a.price/(Select Sum(aa.Price) from @Item aa where aa.[Check] = 'Y'))) as Calculatedfrom @Item across Join@ItemColumns bwhere a.[Check] = 'y'
/* RESULTS1 001 200 Y 1000 200.0000001 001 200 Y 2000 400.0000002 002 300 Y 1000 300.0000002 002 300 Y 2000 600.0000003 003 500 Y 1000 500.0000003 003 500 Y 2000 1000.000000I would strongly suggest using a Reporting tool to display the results properly rather then converting sql row data into colums.*/