exec执行错误,无法在向表插入变量时将 EXECUTE 用作源。

jxf_yx 2004-04-15 04:24:33
insert into @indextable(nid) exec ('select UserID from UserInfo where '+ @condition + 'order by UserID desc')
select O.UserID,O.[8751ID],O.UserName,O.TrueName,O.Sex,O.BirthDay,O.PublicEmail,O.Education,O.Province,O.City,O.Corporation from UserInfo O,@indextable t where O.UserID=t.nid
and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
============
无法在向表插入变量时将 EXECUTE 用作源。
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxf_yx 2004-04-15
  • 打赏
  • 举报
回复
ok了。
能否帮忙看下,下面的存储过程有分页上有错吗?
================================
--复合查询,带分页处理
CREATE procedure TAVAuThDB_UserInfo_SearchUserInfo
(@UserID VarChar,
@p8751ID Int,
@UserName VarChar,
@Sex Int,
@BirthDayStart DateTime,
@BirthDayEnd DateTime,
@Education VarChar,
@Province VarChar,
@City VarChar,
@ChatSvrIP VarChar,
@pagesize int,--每页显示的条数
@pageindex int,--页码
@docount bit=1)
as
Declare @condition varchar(300)
if (@UserID<>null)
select @condition=' userid=@userid and'
if (@p8751ID<>null)
select @condition=@condition + ' [8751ID]=@p8751ID and'
if (@UserName<>null)
select @condition=@condition + ' UserName=@UserName and'
if (@Sex<>null)
select @condition=' Sex=@Sex and'
--
if (@BirthDayStart<>null)
select @condition=@condition + ' BirthDay between @BirthDayStart and @BirthDayEnd and'
if (@Education<>null)
select @condition=@condition + ' Education=@Education and'
if (@Province<>null)
select @condition=@condition + ' Province=@Province and'
if (@City<>null)
select @condition=@condition + ' City=@City and'
if (@ChatSvrIP<>null)
select @condition=@condition + ' ChatSvrIP=@ChatSvrIP'

set nocount on
if(@docount=1)
exec ('select count(UserID) from UserInfo where' + @condition)
else
begin

declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
create table #pageindex(id int identity(1,1) not null,nid int)
set rowcount @PageUpperBound
insert into #indextable(nid)
exec ('select UserID from UserInfo where '+ @condition + 'order by UserID desc')
select O.UserID,O.[8751ID],O.UserName,O.TrueName,O.Sex,O.BirthDay,O.PublicEmail,O.Education,O.Province,O.City,O.Corporation from UserInfo O,#indextable t where O.UserID=t.nid
and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
end
set nocount off
GO
=======================
progress99 2004-04-15
  • 打赏
  • 举报
回复
表變量不支持,用臨時表吧。


create table #indextable (nid varchar(10))
insert into #indextable(nid)
exec ('select UserID from UserInfo where '+ @condition + 'order by UserID desc')

zjcxc 元老 2004-04-15
  • 打赏
  • 举报
回复
--不支持向表变量插入值,只能用临时表或正式表

--改临时表就行了
create table #t(nid int)
insert #t exec ('select UserID from UserInfo where '+ @condition + 'order by UserID desc')

34,590

社区成员

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

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