34,576
社区成员
发帖
与我相关
我的任务
分享
'这样看起来舒服些...'
--------------------SQL Server数据格式化工具-------------------
---------------------------------------------------------------
-- DESIGNER :happycell188(喜喜)
-- QQ :584738179
-- Development Tool :Microsoft Visual C++ 6.0 C Language
-- FUNCTION :CONVERT DATA TO T-SQL
---------------------------------------------------------------
-- Microsoft SQL Server 2005
-- Developer Edition on Microsoft Windows XP [版本 5.1.2600]
---------------------------------------------------------------
---------------------------------------------------------------
use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
ID char(3),
jno char(3)
)
go
--插入测试数据
insert into tb select '1','j1'
union all select '4','j3'
union all select '3','j4'
union all select '7','j3'
union all select '5','j1'
union all select '9','j2'
union all select '8','j1'
go
--代码实现
if object_id('test.dbo.proc_test') is not null drop proc proc_test
go
create proc proc_test
@idinput varchar(10),
@i int
as
begin
declare @idd varchar(10)
if object_id('test.dbo.#t') is not null drop table #t
select idd=row_number()over(order by getdate()),* into #t from tb
select @idd=idd from #t where ID=@idinput
select ID from #t where idd=@idd+3 or idd=@idd-3
end
go
--> 测试存储过程
exec proc_test 5,3
/*
ID
-------
4
*/
exec proc_test 7,3
/*
ID
-------
1
8
*/
declare @num int
select * from a where sno between @num-3 and SNO=@num+3