You help me find this stored procedure, and always said I did not define a variable (Thank you, anxious, online)

Category: MS-SQL Server -> Foundation Classes Author: lotruay Date: 2005-07-24 13:28:02
 
lotruay
2005-07-24 13:28:02
create proc Proc_Pivot
@ TableName varchar (400),
@ GroupName varchar (400),
@ HeadColumn varchar (400),
@ SumName varchar ( 400)
as
Declare @ Sql varchar (800)
Declare @ Count int
Declare @ boby varchar (400)
Declare @ i int
select @ Count = count (Distinct @ HeadColumn) from @ TableName
set @ i = 1
while (@ i <= @ Count)
begin
select distinct Top @ i @ boby = @ HeadColumn from @ TableName order asc
set @ Sql = @ Sql + "SUM (CASE" + @ HeadColumn + "WHEN" + @ boby + "THEN" + @ SumName + " ; ELSE 0 END) AS "+ @ boby +", "
set @ i = @ i +1
end
SELECT @ GroupName as ; @ GroupName, @ Sql
FROM @ TableName
GROUP BY @ GroupName
heqin93
2005-07-24 13:46:17
use dynamic statement: If last changed

exec ('SELECT' + @ GroupName + 'as @ GroupName,' + @ Sql + '
FROM' + @ TableName + '
GROUP BY' + @ GroupName)
zyprainy3
2005-07-24 13:55:41
table / field names can not use variables.
enjoyibusiness
2005-07-24 13:58:26
ah? I according to the parameters passed to the specified query table name, change how to write ah
Zou brother ~ ~! !
zjsnet
2005-07-24 14:08:39
is to use single quotes or double quotes ah?
marongbbjk
2005-07-24 14:13:49
Thank you
get

Oh ...........