Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   Bases de Datos General (http://www.forosdelweb.com/f21/)
-   -   if dentro de un case (http://www.forosdelweb.com/f21/if-dentro-case-316766/)

Punktruka 14/07/2005 14:14

if dentro de un case
 
holas... me gustaria saber si se puede inkluir un if dentro de un case en sql, porke tengo el siguiente kodigo de un procedimiento y me da error de sintaxis..
Código:

case descrip_form.tipo
                  when 't' then
                        convert(nvarchar(4000),isnull(valor_hist.v_t,'--'))
                  when 's' then
                        convert(nvarchar(800),isnull(valor_hist.v_t,'--'))
                  when 'c' then                       
                        if exists(select cod_ubic from valor_hist where cod_ubic = @cod_ubic and cod_campo = '4263')
                        begin
                                set @var='s'
                                select @var as mercado
                        end
                        else
                        begin
                                set @var='n'
                                select @var as mercado
                        end
                  when 'm' then
                        convert(nvarchar(4000),isnull(valor_hist.v_m,'--'))
                  when 'n' then
                        convert(nvarchar(200),convert(int,isnull(valor_hist.v_n,'0')))
                  when 'f' then
                        convert(nvarchar(10),isnull(valor_hist.v_f,null) ,103)
                  when 'e' then
                        'Titulo'
        else '--'
        end
        as valor

porfis ayuyaaaaa

Sir Matrix 14/07/2005 14:55

Hola, no puedes incluir el if en ese lugar; pero en lugar de usar ese if puedes usar otro case:

case descrip_form.tipo
when 't' then
convert(nvarchar(4000),isnull(valor_hist.v_t,'--'))
when 's' then
convert(nvarchar(800),isnull(valor_hist.v_t,'--'))
when 'c' then
case when (select cod_ubic from valor_hist where cod_ubic = @cod_ubic and cod_campo = '4263') is not null
then
set @var='s'
select @var as mercado
else
set @var='n'
select @var as mercado
end
when 'm' then
convert(nvarchar(4000),isnull(valor_hist.v_m,'--'))
when 'n' then
convert(nvarchar(200),convert(int,isnull(valor_his t.v_n,'0')))
when 'f' then
convert(nvarchar(10),isnull(valor_hist.v_f,null) ,103)
when 'e' then
'Titulo'
else '--'
end
as valor

Punktruka 14/07/2005 16:17

ok muuuuuuuuxaaas.. gracias por tu ayuda. :adios:


La zona horaria es GMT -6. Ahora son las 19:39.

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.