Buscando info en la red encontre este ejemplo:
Código:
CREATE PROCEDURE gastos
@tabla varchar(255),
@pivot varchar(255),
@agrupacion varchar(255),
@campo varchar(255),
@calculo varchar(20)
as
declare @strg as varchar(8000)
declare @sql as varchar(8000)
create table #pivot(pivot varchar(8000))
set @strg="
set @sql="
set @strg=@strg+'insert into #pivot select distinct'''+@calculo+'(case when'+@pivot+'=''''''+rtrim(cast('+@pivot+'as varchar(500)))+'''''' then'+@campo+'else null end) as '''''+@calculo+'_''+rtrim(cast('+@pivot+'as varchar(500)))+'''''',''as pivot from'+@tabla+'where'+@pivot+'is not null'
execute(@strg)
set @sql='select'
select @sql=@sql+rtrim(convert(varchar(500),pivot))
from #pivot order by pivot
if @agrupacion<>'*'
begin
set @sql=@sql+@agrupacion+'from'+@tabla+'group by'+@agrupacion
end
else
begin
set @sql=@sql+'''todos'' as t form'+@tabla
end
GO
y en mi pagina de ASP.Net puse:
Código:
ub crosstab(sender as system.object, e as system.eventargs)
dim myDataAdapter_1 as sqlDataAdapter
dim myCommand as SqlCommand
dim myDataset_1 as Dataset
conexion.open()
mydataadapter_1=new sqldataadapter("iusr_acix.SP_finanzas", conexion)
mydataadapter_1.selectcommand.commandtype=commandtype.storedprocedure
mydataadapter_1.selectcommand.parameters.add(new sqlparameter("@tabla",sqldbtype.varchar, 8000))
mydataadapter_1.selectcommand.parameters.add(new sqlparameter("@pivot",sqldbtype.varchar, 8000))
mydataadapter_1.selectcommand.parameters.add(new sqlparameter("@agrupacion",sqldbtype.varchar, 8000))
mydataadapter_1.selectcommand.parameters.add(new sqlparameter("@campo",sqldbtype.varchar, 8000))
mydataadapter_1.selectcommand.parameters.add(new sqlparameter("@calculo",sqldbtype.varchar, 8000))
mydataadapter_1.selectcommand.parameters("@tabla").value="dbo.gastos"
mydataadapter_1.selectcommand.parameters("@pivot").value="gastos.ctta"
mydataadapter_1.selectcommand.parameters("@agrupacion").value="gastos.periodo"
mydataadapter_1.selectcommand.parameters("@campo").value="gastos.monto"
mydataadapter_1.selectcommand.parameters("@calculo").value="sum"
mydataset_1=new dataset
mydataadapter_1.fill(mydataset_1)
dg_2.datasource=mydataset_1
dg_2.databind()
conexion.close()
End Sub
Pero me pone un error que dice:
Cita: Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'insert'. Line 2: Incorrect syntax near 'varchar'.
En esta linea, la 98:
Cita: Source Error:
Line 96:
Line 97: mydataset_1=new dataset
Line 98: mydataadapter_1.fill(mydataset_1)
Line 99: dg_2.datasource=mydataset_1
Line 100:dg_2.databind()
Es correcto lo que esto haceindo?
En que momento le indico que me tome los valores de mi formulario (DropDownList, RadioButtonList, Etc.)
Si me pueden ayudar por favor que de todos modo yo he de buscar......jejejej