如何获取尾数为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
*/