存储过程如何传递条件进去? 写多个太麻烦了

lijing3333 2011-11-10 04:16:42

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



create procedure [dbo].[P_AdminToDDTJ]
(@startIndex int,
@endIndex int,@tj varchar(200)
)
as
set nocount on
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select [oId] from [LFDSDB].[dbo].[orderInfo] where @tj order by [oId] desc
SELECT o.[oId]
,o.[oCode]
,o.[money]
,o.[accounts]
,o.[state]
,o.[ip]
,o.[addDate]
,o.[remark]
,o.[userID]
,o.[jyCode]
FROM [LFDSDB].[dbo].[orderInfo] o
inner join @indextable t on
O.[oId]=t.nid
where t.id between @startIndex and @endIndex and @tj order by t.id
set nocount off
RETURN






这个动态的条件 @tj 是如何传递进去的 ? 求教了
...全文
91 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mr_Nice 2011-11-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ssp2009 的回复:]

SQL code
exec('
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select [oId] from [LFDSDB].[dbo].[orderInfo] where '+@tj+' order by [oId] ……
[/Quote]

这个意思啊,动态拼接了...
NBDBA 2011-11-10
  • 打赏
  • 举报
回复
set rowcount
在不久的版本会废除,现在的项目不应该再使用
NBDBA 2011-11-10
  • 打赏
  • 举报
回复
找找通用的动态分页存储过程,你这个用法太笨拙了,弃之不用为好
快溜 2011-11-10
  • 打赏
  • 举报
回复
exec('
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select [oId] from [LFDSDB].[dbo].[orderInfo] where '+@tj+' order by [oId] desc
SELECT o.[oId]
,o.[oCode]
,o.[money]
,o.[accounts]
,o.[state]
,o.[ip]
,o.[addDate]
,o.[remark]
,o.[userID]
,o.[jyCode]
FROM [LFDSDB].[dbo].[orderInfo] o
inner join @indextable t on
O.[oId]=t.nid
where t.id between '''+@startIndex+''' and '''+@endIndex+' and '+@tj+' order by t.id')
lijing3333 2011-11-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 orchidcat 的回复:]
create procedure [dbo].[P_AdminToDDTJ]
(@startIndex int,
@endIndex int,@tj varchar(200)
)


@tj 应该是写好的 Col = *****
[/Quote]

什么意思啊? 我想从外部传进来 但是报错了。。。。
Mr_Nice 2011-11-10
  • 打赏
  • 举报
回复
create procedure [dbo].[P_AdminToDDTJ]
(@startIndex int,
@endIndex int,@tj varchar(200)
)


@tj 应该是写好的 Col = *****

34,575

社区成员

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

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