Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/04/2011, 14:39
arielukos
 
Fecha de Ingreso: febrero-2010
Mensajes: 7
Antigüedad: 14 años, 2 meses
Puntos: 0
Error Parametro Pivot - Create Procedure

Hola a todos, resulta que estoy trabajando con C# , ASP.Net y SQL Server 2008, estoy pivoteando unos datos pero sin embargo la consulta me genera un error , especificamente me dice que debo declarar la variable @asig, les muestro la consulta para que me den su idea:

Aqui esta el procedimiento:

CREATE PROCEDURE NOTAS
@asig nvarchar(4000)
AS
DECLARE @cols NVARCHAR(4000)
SELECT @cols = COALESCE(@cols +',['+NOTA_NOMBRE+']', '['+NOTA_NOMBRE+']')
FROM Nota
GROUP BY NOTA_NOMBRE

DECLARE @query NVARCHAR(4000)
SET @query = 'SELECT * FROM Nota WHERE ASIG_ID = @asig
PIVOT(MAX(NOTA) FOR NOTA_NOMBRE IN('+@cols+')) AS PivotTable'
EXECUTE(@query)

y aqui la llamada:

DataTable dt = new DataTable();
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrin gs["sica"].ToString()))
{
connection.Open();
SqlCommand cmd = new SqlCommand("NOTAS", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@asig", idasignatura);

SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}

como les dije el problema, es que no reconocer el parametro @asig como puedo solucionar esto??? Gracias de antemano.