首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么获取尾数为8的数字?

2012-01-09 
如何获取尾数为8的数字?急~!在线等如:取职范围是1-1000获取尾数为8、88、888的数字,用sql语句怎么写?谢谢~![

如何获取尾数为8的数字?急~!在线等
如:
取职范围是1-1000   获取尾数为8、88、888的数字,用sql语句怎么写?
谢谢~!

[解决办法]
错了哦,改下

declare @beg int
declare @end int
set @beg=1
set @end=100000

declare @x int
set @x=8

declare @y int

while @x <@end
begin
print @x
set @y=@x*10
set @x=@y+8
end

--结果
8
88
888
8888
88888


[解决办法]
if object_id( 'tempdb..#tmp ') is not null
drop table #tmp
GO
select top 1000 id = identity(int,1,1) into #tmp from syscolumns as a,sysobjects as b,syscolumns as c

SELECT id FROM #tmp WHERE
right(rtrim(id),1) = '8 ' or
right(rtrim(id),2) = '88 ' or
right(rtrim(id),3) = '88 '

drop table #tmp
[解决办法]
Select Top 1000 ID = Identity(Int, 1, 1) Into #T From Syscolumns A, Sysobjects B

Select * From #T Where ID = 8 Or ID = 88 Or ID = 888

Drop Table #T
--Result
/*
ID
8
88
888
*/

热点排行