我有如下代码想实现对i的最后两个数值进行判断,从而得到相应的值来限制J的取值,不知该如何实现,能否用CASE进行判断,还望大家赐教
declare @i int
declare @j int
declare @k int
declare @sql nvarchar(4000)
set @i=201101
set @j=1
while @i<=201103
begin
******
******
[email protected][email protected],
判断的依据为:[email protected];[email protected];[email protected]
while @j<[email protected]
begin
select @sql=isnull(@sql+' union all','')+' select * from '+str(@i,6)+'.dbo.'+str(@[email protected],8)
set @[email protected]+1
end
set @[email protected]+1
end
select @sql
exec(@sql)
望到家给予帮助,谢谢。
------解决方案--------------------
可以.
------解决方案--------------------
- SQL code
select @k = case right(@i,2) when 1,2,6,11 then 26 when 3,4,10 then 27 else 28 end
------解决方案--------------------
我觉得用if else会更好点
------解决方案--------------------
- SQL code
select 100+number as col1, case when right(100+number,2) in (1,2,6,11) then 26 when right(100+number,2) in (3,4,10) then 27 else 28 end as col2from master..spt_values where type='p' and number <15/*col1 col2----------- -----------100 28101 26102 26103 27104 27105 28106 26107 28108 28109 28110 27111 26112 28113 28114 28*/