我想要sql查询读取数据我希望数据在两个字段前和两个字段后给出id [英] i want sql query for reading data i want data giving id with before two fields and after two fields

查看:88
本文介绍了我想要sql查询读取数据我希望数据在两个字段前和两个字段后给出id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要sql查询来读取数据



1080200032060120121019130214这是一个id,就像在我的表中有13个ID。只是为了理解我这样给予



i want sql query for reading data

1080200032060120121019130214 this is one id like in my table having 13 ids. just for understanding i am giving like this

108020003 20601 20121019130214
108020003 20602 20121019130734
108020003 20603 20121019131157
108020003 20604 20121019131714
108020003 20605 20121019132137
108020003 20606 20121019141036
108020003 20607 20121019141451
108020003 20608 20121019141957
108020003 20609 20121019142735
108020003 20610 20121019144434
108020003 20611 20121019145003
108020003 20612 20121019145450
108020003 20613 20121019150619



id数据类型是nvarchar



i就像这种格式一样。基于20601到20613读取数据。



i给出id为10802000320607,我希望数据在两个字段之前和两个字段之后给出id




id datatype is nvarchar

i am giving like this format. based on 20601 to 20613 read data.

i am giving id as 10802000320607 , i want data giving id with before two fields and after two fields

1080200032060520121019132137
1080200032060620121019141036
1080200032060720121019141451
1080200032060820121019141957
1080200032060920121019142735







plz帮帮我。




plz help me.

推荐答案

你是说:

你在nvarchar类型的桌子上有一列

它是28个字符

你得到前14个字符

你需要返回以这两个字符开头的行,前两行和后两行,按该列排序?



如果是这样



类似



Are you saying:
You have a single column on the table of type nvarchar
It is 28 characters long
You are given the first 14 characters
You need to return the row starting with those two characters, and the two rows before and two rows after, sorted by that column?

If so

something like

Select top 3 from table
where id > @givenId
order by id

union

select top 2 from table
where id < @givenid
order by id desc





对不起我前面没有sql server我来看看它,但看起来对我来说是正确的!



Sorry I don''t have sql server in front of me to check it out but it looks right to me!


这篇关于我想要sql查询读取数据我希望数据在两个字段前和两个字段后给出id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆