存储过程中一个表的某个字段值为另一个表的表名该如何写啊
存储过程中一个表的某个字段值为另一个表的表名该怎么写啊?
(select tablename from novel_topic where topicid=@topicid)
tablename的值为另一个表的表名
insert into 表名(topicid,chapter,path,length) values(@topicid,@chapter,@path,@length)
这个存储过程该怎么写啊?
------解决方案--------------------
------解决方案--------------------
- -你看你写的与我写的有啥区别呢。。
有简单的写法当然给你写喽,表、列等对象不能用变量表示
需要用字符拼接的方式,用exec来执行
(select tablename from novel_topic where topicid=@topicid)
tablename的值为另一个表的表名
insert into 表名(topicid,chapter,path,length) values(@topicid,@chapter,@path,@length)
这个存储过程该怎么写啊?
存储
insert
------解决方案--------------------
declare @tb nvarchar(50),@sql nvarchar(2000)
select @tb=tablename from novel_topic where topicid=@topicid
set @sql='insert into '+@tb+'(topicid,chapter,path,length) values(@topicid,@chapter,@path,@length)'
exec sp_exeutesql @sql,N'@topicid int,@chapter nvarchar(20)....',@topicid,@chapter...
------解决方案--------------------
- -你看你写的与我写的有啥区别呢。。
有简单的写法当然给你写喽,表、列等对象不能用变量表示
需要用字符拼接的方式,用exec来执行