当前位置: 代码迷 >> Sql Server >> 怎么获取尾数为8的数字?
  详细解决方案

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

热度:27   发布时间:2016-04-27 20:24:49.0
如何获取尾数为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 @[email protected]*10
set @[email protected]+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
*/
  相关解决方案