set @cj=(select top 1 A01059 from a01 , GW_CODE where gw_code.gw_name=a01.Gw_name )
set @GW_name=
case
when @cj='三'then (select GW_name from GW_CODE where GW_CODE017='三' )
when @cj='四' then (select GW_name from GW_CODE where GW_CODE017='四' )
when @cj='五' then (select GW_name from GW_CODE where GW_CODE017='五' )
when @cj='六' then (select GW_name from GW_CODE where GW_CODE017='六' )
when @cj='七' then (select GW_name from GW_CODE where GW_CODE017='七' )
when @cj='八' then (select GW_name from GW_CODE where GW_CODE017='八' )
when @cj='九' then (select GW_name from GW_CODE where GW_CODE017='九' )
when @cj='十' then (select GW_name from GW_CODE where GW_CODE017='十' )
when @cj='十一' then (select GW_name from GW_CODE where GW_CODE017='十一' )
when @cj='十二' then (select GW_name from GW_CODE where GW_CODE017='十二' )
when @cj='十三' then (select GW_name from GW_CODE where GW_CODE017='十三' )
when @cj='十四' then (select GW_name from GW_CODE where GW_CODE017='十四' )
when @cj='十五' then (select GW_name from GW_CODE where GW_CODE017='十五' )
when @cj='十六' then (select GW_name from GW_CODE where GW_CODE017='十六' )
else null
end
select @GW_name
then语句返回的结果有多个,我想得到结果是多个值,求大神指点。
7 个解决方案
#1
set @GW_name= (select GW_name from GW_CODE where GW_CODE017=@cj)
#2
逻辑有问题.
既然GW_CODE017 在不同值的时候会返回不同的GW_name,那如何又能将它赋给一个变量呢?
既然GW_CODE017 在不同值的时候会返回不同的GW_name,那如何又能将它赋给一个变量呢?
#3
晴天大大说的对。GW_CODE017 取不同值,返回不同的GW_name,怎么又赋值给变量?
#4
那我要怎么做才能实现我想要的结果了,有什么解决方法没
#5
declare @cj varchar(10),@GW_name varchar(30)
set @cj=(select top 1 A01059 from a01 , GW_CODE where gw_code.gw_name=a01.Gw_name )
select GW_name=
case
when @cj='三'then (select GW_name from GW_CODE where GW_CODE017='三' )
when @cj='四' then (select GW_name from GW_CODE where GW_CODE017='四' )
when @cj='五' then (select GW_name from GW_CODE where GW_CODE017='五' )
when @cj='六' then (select GW_name from GW_CODE where GW_CODE017='六' )
when @cj='七' then (select GW_name from GW_CODE where GW_CODE017='七' )
when @cj='八' then (select GW_name from GW_CODE where GW_CODE017='八' )
when @cj='九' then (select GW_name from GW_CODE where GW_CODE017='九' )
when @cj='十' then (select GW_name from GW_CODE where GW_CODE017='十' )
when @cj='十一' then (select GW_name from GW_CODE where GW_CODE017='十一' )
when @cj='十二' then (select GW_name from GW_CODE where GW_CODE017='十二' )
when @cj='十三' then (select GW_name from GW_CODE where GW_CODE017='十三' )
when @cj='十四' then (select GW_name from GW_CODE where GW_CODE017='十四' )
when @cj='十五' then (select GW_name from GW_CODE where GW_CODE017='十五' )
when @cj='十六' then (select GW_name from GW_CODE where GW_CODE017='十六' )
else null
end
#6
那我要怎么做才能实现我想要的结果了,有什么解决方法没
#7
不行哦,=号后面不能有多个值,我想实现的效果是当GW_CODE017等于具体某个值的时候返回所有的GW_name,用什么方法可以解决呀
#1
set @GW_name= (select GW_name from GW_CODE where GW_CODE017=@cj)
#2
逻辑有问题.
既然GW_CODE017 在不同值的时候会返回不同的GW_name,那如何又能将它赋给一个变量呢?
既然GW_CODE017 在不同值的时候会返回不同的GW_name,那如何又能将它赋给一个变量呢?
#3
晴天大大说的对。GW_CODE017 取不同值,返回不同的GW_name,怎么又赋值给变量?
#4
那我要怎么做才能实现我想要的结果了,有什么解决方法没
#5
declare @cj varchar(10),@GW_name varchar(30)
set @cj=(select top 1 A01059 from a01 , GW_CODE where gw_code.gw_name=a01.Gw_name )
select GW_name=
case
when @cj='三'then (select GW_name from GW_CODE where GW_CODE017='三' )
when @cj='四' then (select GW_name from GW_CODE where GW_CODE017='四' )
when @cj='五' then (select GW_name from GW_CODE where GW_CODE017='五' )
when @cj='六' then (select GW_name from GW_CODE where GW_CODE017='六' )
when @cj='七' then (select GW_name from GW_CODE where GW_CODE017='七' )
when @cj='八' then (select GW_name from GW_CODE where GW_CODE017='八' )
when @cj='九' then (select GW_name from GW_CODE where GW_CODE017='九' )
when @cj='十' then (select GW_name from GW_CODE where GW_CODE017='十' )
when @cj='十一' then (select GW_name from GW_CODE where GW_CODE017='十一' )
when @cj='十二' then (select GW_name from GW_CODE where GW_CODE017='十二' )
when @cj='十三' then (select GW_name from GW_CODE where GW_CODE017='十三' )
when @cj='十四' then (select GW_name from GW_CODE where GW_CODE017='十四' )
when @cj='十五' then (select GW_name from GW_CODE where GW_CODE017='十五' )
when @cj='十六' then (select GW_name from GW_CODE where GW_CODE017='十六' )
else null
end
#6
那我要怎么做才能实现我想要的结果了,有什么解决方法没
#7
不行哦,=号后面不能有多个值,我想实现的效果是当GW_CODE017等于具体某个值的时候返回所有的GW_name,用什么方法可以解决呀