如何得到exec(@selSql)后的数据

loulanlouzhu 2005-04-07 08:06:14
类似


declare @selSql varchar(1000)
set @selSql = 'select ParentDepart from Common_Department where DepartID = @DepartID '
delete from Common_Department where DepartID in (exec(@selSql))
...全文
130 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
loulanlouzhu 2005-04-07
  • 打赏
  • 举报
回复
可以了!

稍微改下exec ('delete from Common_Department where DepartID in ('+@selSql + ')')
loulanlouzhu 2005-04-07
  • 打赏
  • 举报
回复
在关键字 'select' 附近有语法错误
loulanlouzhu 2005-04-07
  • 打赏
  • 举报
回复
exec(@selSql)返回的是多个值,怎么取道这些值呢?
winternet 2005-04-07
  • 打赏
  • 举报
回复
declare @selSql varchar(1000)
set @selSql = 'select ParentDepart from Common_Department where DepartID ='+ cast(@DepartID as varchar) --這裡變下

exec ('delete from Common_Department where DepartID in '+@selSql) --這裡也變下
loulanlouzhu 2005-04-07
  • 打赏
  • 举报
回复
我知道错的!
只是表达一下我的意思!

感谢帮助!

我试试看!
talantlee 2005-04-07
  • 打赏
  • 举报
回复
上面語法錯誤,你自己參照我的
-create by talantlee
--=====4/2/2005
--===use from檢驗密碼
---check_id2 'andy','123456',''
--===測試通過

CREATE PROCEDURE check_id2
@UserID varchar(50) ,
@Password varchar(50),
@reason int output

AS



declare @sql nvarchar(1000)
set @sql=N'select @a=count(*) from admin where UserID='''+@UserID+''''

set @sql=@sql+N' and Password='''+@Password+''''


exec sp_executesql @sql,N'@a int output',@reason output



GO
你在外面定義一個變量 把上面的output型賦它
下面是函數

---====create by talantlee 3/28/2005
---=====用來取值如 @sql='FG.BF.BC.T23-12' 則返回BC
----====print hh_li.dbo.test1('FG.BF.BC.T23-12')
CREATE function test1(@sql varchar(1000))
RETURNS varchar(1000)

as
begin
--declare @sql varchar (1000)
declare @a varchar(1000)
declare @b int
set @b=0

while (@b<2) ---這裡決定取小數點第幾位
begin
set @a=left(@sql,patindex('%.%',@sql))
set @sql=replace(@sql,@a,'')
set @b=@b+1
end
--if(patindex('%.%',@sql)<1)
--return @a
--else
return left(@sql,patindex('%.%',@sql)-1)
end

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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