存储过程的问题.

ljren_t 2001-12-26 03:38:01
select @Name=name,@tID=parentID from area where ID= @tID
表名我想用变量,可这样写出错.
select @Name=name,@tID=parentID from @tType where ID= @tID
应该怎么写?
...全文
88 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljren_t 2002-01-04
  • 打赏
  • 举报
回复
谢谢各位.
tommychim 2001-12-26
  • 打赏
  • 举报
回复
declare @name varchar(20),@tid int,@tablename varchar(20),@sql nvarchar(800)
set @sql ='select @name=name,@tid=parentid from '+@tablename+' where id=@tid'
execute sp_executesql @sql,N'@name varchar(20) output,@tid int output',
@p1 output,@p2 output
print @p1
print @p2
tommychim 2001-12-26
  • 打赏
  • 举报
回复
Declare @SQL NVarchar(500),@Table_Name Varchar(20),@Filtered Char(2)
Select @Table_Name='vcrRepairDetail'
Select @Filtered='11'
Select @SQL='Select * From '+@Table_Name+' Where DocNo Like '''+@Filtered+'%'''
Exec sp_executesql @SQL
net_steven 2001-12-26
  • 打赏
  • 举报
回复
动态sql:
declare @csql varchar(200)
select @csql='declare @Name varchar(50),@tID int '
select @csql=@csql+'select @Name=name,@tID=parentID from '+@tType+'where ID= '+cast(@tID as varchar(50))
execute(@csql)
guasha 2001-12-26
  • 打赏
  • 举报
回复
select @sql='......'
exec(@sql)

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧