注册 登录
编程论坛 SQL Server论坛

帮忙看下那里错了...谢谢拉

uatoily 发布于 2007-12-04 15:58, 959 次点击
提示说@tbName 没有定义
我不是定义了....为什么会出错?
在insert那里的@tbName 出错了..要怎么改?
create proc InsertLogin
(
@UserType varchar(10)
)
as
declare @tbName varchar(10)
set @tbName=
case @UserType
    when 'a'  then 'hello'
     when 'b' then 'good'
end
insert @thName values('mygod')
7 回复
#2
sky_yang_sky2007-12-04 16:02
要定義字段
#3
XieLi2007-12-04 16:12
要懂得INSERT的意思
#4
uatoily2007-12-04 16:18
那要怎么改?麻烦帮我改下。。。让我学习下...谢谢
#5
uatoily2007-12-04 16:22
我知道 insert 后面要跟着表名 我用@tbName代表表名,为什么不行
#6
purana2007-12-04 16:22
create proc InsertLogin
    @UserType varchar(10)
as
    declare @tbName varchar(10)
    select @tbName=case @UserType
                      when 'a'  then 'hello'
                      when 'b' then 'good'
                   end

    exec('insert '+@tbName+' values(''mygod''')
go

这样试试.
#7
XieLi2007-12-04 16:26
楼上解决了!
#8
uatoily2007-12-04 16:39
哦...谢谢拉...原来用exec执行
1