日期:2014-05-18  浏览次数:20548 次

这个过程有错?
if   exists(select   name   from   sysobjects   where   name= 'Tview '   and   type= 'P ')
drop   procedure   Tview
go

create   procedure   Tview  
(@deptname   varchar(15))
as
declare   @sql   varchar(2000)

set   @sql= 'create   view   choice_view   as   select   *   from   choice       where   left(course_no,2)
  in
(select   dept_no   from   dept   where   dept_name= '+ ' ' '+@deptname+ ' ' '+ ') '

exec   (@sql)

go

------解决方案--------------------
可以實現的,樓主的代碼只要稍微修改即可。

if exists(select name from sysobjects where name= 'Tview ' and type= 'P ')
drop procedure Tview
go

create procedure Tview
(@deptname varchar(15))
as
if exists(select name from sysobjects where name= 'choice_view ' and type= 'V ')
drop view choice_view --加上代碼判斷choice_view是否存在,存在就先刪除

declare @sql varchar(2000)

set @sql= 'create view choice_view as select * from choice where left(course_no,2)
in
(select dept_no from dept where dept_name= ' ' '+ @deptname+ ' ' ') ' --你的拼結語句寫的有問題,需要修改為如此
exec(@sql) --全角的括號改為半角的

go