+ -
当前位置:首页 → 问答吧 → SQL的存储过程好纠结,高手指教一下

SQL的存储过程好纠结,高手指教一下

时间:2011-12-19

来源:互联网

create procedure CreateCusView
@ID varchar(18)
as
begin
exec('create view OrderForCus
  as
  select 订单.*,订单商品.商品,订单商品.客户评价
  from 订单,订单商品
  where 订单.订单号=订单商品.订单号
  and 订单.客户='+@ID);
exec('grant select update(客户评价) on OrderForCus to '+@ID);
end
建了一个创建视图的存储过程,可是执行的时候
USE [ShopOnline]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[CreateCusView]
@ID = N'''u17'''

SELECT 'Return Value' = @return_value

GO
总是有错
消息 102,级别 15,状态 1,第 1 行
'select' 附近有语法错误。
把那个键视图的语句单独贴到SQL中执行就没问题。。。无语了。。。高手不要路过啊,救命。。。。

作者: makailove1   发布时间: 2011-12-19

动态创建的视图是临时的,再语句执行完毕后就不存在了,所以你后面的exec('grant select update(客户评价) on OrderForCus to '+@ID);
是找不到它的

作者: ssp2009   发布时间: 2011-12-19

SQL code
create procedure CreateCusView
@ID varchar(18)
as
begin
create view OrderForCus
  as
  select 订单.*,订单商品.商品,订单商品.客户评价
  from 订单,订单商品
  where 订单.订单号=订单商品.订单号
  and 订单.客户=@ID;
grant select update(客户评价) on OrderForCus to @ID;
end


很少由存储过程来创建视图的!

作者: qianjin036a   发布时间: 2011-12-19

为什么要动态创建视图?

作者: fredrickhu   发布时间: 2011-12-19