Click here to Skip to main content
15,308,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all i have 10 different rows and 10 different columns in sql. for each row there is one common column called quantity. now i have to multiply the no present in the quantity for the rest of the rows for each and every column. how can i accomplish this? sample table is shown below.

sno quantity a1 b1 c1 d1
1 5 4 10 11 9
2 4 2 8 10 7
3 6 2 3 1 9

so my output should be:



sno quantity a1 b1 c1 d1
1 5 20 50 55 45
2 4 8 32 40 28
3 6 12 18 06 45
Posted

1 solution

Try this code


SQL
Create table #temp
(Id int identity(1,1),
quantity int,
a1 int,
b1 int,
c1 int,
d1 int
)
insert into #temp Values (5,4,10,11,9),(4,2,8,11,9),(6,3,10,1,9)


SELECT Id, quantity,(a1*quantity) as A1,(b1*quantity) as B1,(c1*quantity) as C1,
(d1*quantity) as D1 from #temp

DROP table #temp
   
Comments
kparun86 3-Feb-14 5:09am
   
Ok Thanks Sandeep.
Sandeep Singh Shekhawat 3-Feb-14 5:10am
   
Welcome to you..

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