视图和存储过程的问题。
对于下面的sql语句,怎么改成能在sqlserver2008的视图中执行吗?
如果改不了视图要怎么建立存储过程,大神们教我怎么建立存储过程,最好步骤详细点。
declare @str varchar(8000)
select @str=''
select @str=@str+convert(varchar(10),BO_ZH_WBX_S.RQ,120)+',' from BO_ZH_WBX_S,BO_ZH_BX_P WHERE BO_ZH_WBX_S.BINDID=BO_ZH_BX_P.HIDE
select @str as HEBING
select RQ,FYKMBM,FYKMMC,JE,BZ from BO_ZH_GZRZ_P,BO_ZH_GZRZ_S where BO_ZH_GZRZ_P.BINDID=BO_ZH_GZRZ_S.BINDID and CHARINDEX(convert(varchar(10),BO_ZH_GZRZ_P.RQ,120),@str,1)>0 and BO_ZH_GZRZ_P.isend=1 group by RQ,FYKMBM,FYKMMC,JE,BZ
go
------解决方案--------------------格式化了一下,这样:
--创建存储过程
create proc dbo.proc_name
as
declare @str varchar(8000)
select @str=''
select @str=@str+convert(varchar(10),BO_ZH_WBX_S.RQ,120)+','
from BO_ZH_WBX_S,BO_ZH_BX_P
WHERE BO_ZH_WBX_S.BINDID=BO_ZH_BX_P.HIDE
select @str as HEBING
select RQ,FYKMBM,FYKMMC,JE,BZ
from BO_ZH_GZRZ_P,BO_ZH_GZRZ_S
where BO_ZH_GZRZ_P.BINDID=BO_ZH_GZRZ_S.BINDID and
CHARINDEX(convert(varchar(10),BO_ZH_GZRZ_P.RQ,120),@str,1)>0 and
BO_ZH_GZRZ_P.isend=1
group by RQ,FYKMBM,FYKMMC,JE,BZ
go