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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 cross table query via stored procedure

Author  Topic 

jonekim
Starting Member

35 Posts

Posted - 2012-05-14 : 11:18:48
I've a table
SALES

create table sales (empId int not null, prdId varchar(8) not null, priceOfPrd money not null)

I've written pivot table query as one of my requirement, but how to create stored procedure for this pivot table??

select empid, [p1] as p1,[p2] as p2,[p3] as p3,[p4] as p4
from
(
select empid,pid,price from sales
) _sales
pivot
(
sum(price)
for pid in ([p1],[p2],[p3],[p4])
) as pvt


are there any tutorials to learn about creating stored procedure for pivot tables?

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2012-05-14 : 12:28:46
Store procedure is a code of block ,You can write any DML ,DDL operation in it.

For Exampl:


Create Procedure <NameoProc> ( parameter datatype....)
as
begin

your code


end

Vijay is here to learn something from you guys.
Go to Top of Page
   

- Advertisement -