i have columns named col1,col2, to col12 and I have exm1,exm2 to exm12.
我有col1,col2到col12的列,我有exm1,exm2到exm12。
how can I do this?
我怎样才能做到这一点?
declare @i= 1
do until i=12
(
case
when col@i <= 25000 then '1. xxxx <= 25K '
when col@i > 25000 and col@i <=100000 then '2. 25K < xxxx <= 100K '
when col@i > 100000 then '6. xxxx >= 100K '
else end as column_group_@1
set i=i+1
)
same with exm1
与exm1相同
1 个解决方案
#1
0
IF OBJECT_ID('tempdb..#temp1') IS NOT NULL DROP TABLE #temp1
GO
create table #Temp1(col@i int)
IF OBJECT_ID('tempdb..#temp2') IS NOT NULL DROP TABLE #temp2
GO
create table #Temp2(qrystr varchar(max))
declare @i int
declare @strcon varchar(5)
declare @qrystr varchar(max)
set @i= 1
while(@i<12)
begin
set @strcon=rtrim(ltrim(str(@i)))
set @qrystr='
select
(
case
when col' + @strcon + '<= 25000 then ''1. xxxx <= 25K ''
when ' + @strcon +'> 25000 and ' + @strcon +' <=100000 then ''2. 25K < xxxx <= 100K ''
when '+ @strcon +'> 100000 then ''6. xxxx >= 100K ''
end
)as column_group_@1
from YourTableName'
Insert Into #Temp2 values(@qrystr)
set @i=@i+1
end
Select * From #Temp2
#1
0
IF OBJECT_ID('tempdb..#temp1') IS NOT NULL DROP TABLE #temp1
GO
create table #Temp1(col@i int)
IF OBJECT_ID('tempdb..#temp2') IS NOT NULL DROP TABLE #temp2
GO
create table #Temp2(qrystr varchar(max))
declare @i int
declare @strcon varchar(5)
declare @qrystr varchar(max)
set @i= 1
while(@i<12)
begin
set @strcon=rtrim(ltrim(str(@i)))
set @qrystr='
select
(
case
when col' + @strcon + '<= 25000 then ''1. xxxx <= 25K ''
when ' + @strcon +'> 25000 and ' + @strcon +' <=100000 then ''2. 25K < xxxx <= 100K ''
when '+ @strcon +'> 100000 then ''6. xxxx >= 100K ''
end
)as column_group_@1
from YourTableName'
Insert Into #Temp2 values(@qrystr)
set @i=@i+1
end
Select * From #Temp2