当前位置: 代码迷 >> Sql Server >> 使用Gridview绑定SQL存储过程出现有关问题.
  详细解决方案

使用Gridview绑定SQL存储过程出现有关问题.

热度:20   发布时间:2016-04-27 16:45:34.0
使用Gridview绑定SQL存储过程出现问题..
create   proc     cj_data
@p_cj_bid   int
as
begin
declare   @sql   varchar(8000)
set   @sql= 'select     cj_name   as   姓名,cj_xh   as   学号, '
select   @[email protected]+ '[ '+km_name+ ']=sum(case   when   cj_kmid= ' ' '+km_dh+ ' ' '   then   cj_cj   else   0   end), '
from   (select   distinct   km_name,km_dh   from   jw_cj   a   join   jw_km   b   on   a.cj_kmid=b.km_dh   and   [email protected]_cj_bid)   a
set   @sql=substring(@sql,1,len(@sql)-1)
set   @[email protected]+ '   from   jw_cj   where   [email protected]_cj_bid   group   by   cj_name,cj_xh '
exec(@sql)
end
go

测试查询的时候出现   必须声明变量 '@p_cj_bid '
求一正确方法.

------解决方案--------------------
--try


create proc cj_data
@p_cj_bid int
as
begin
declare @sql varchar(8000)
set @sql= 'select cj_name as 姓名,cj_xh as 学号, '
select @[email protected]+ '[ '+km_name+ ']=sum(case when cj_kmid= ' ' '+km_dh+ ' ' ' then cj_cj else 0 end), '
from (select distinct km_name,km_dh from jw_cj a join jw_km b on a.cj_kmid=b.km_dh and [email protected]_cj_bid) a
set @sql=substring(@sql,1,len(@sql)-1)
set @[email protected]+ ' from jw_cj where cj_bid= '[email protected]_cj_bid+ ' group by cj_name,cj_xh '
exec(@sql)
end
go
  相关解决方案