Retroceder   Foros del Web > Programación para sitios web > Bases de Datos

Respuesta
 
Herramientas Desplegado
Antiguo 14-jul-2005, 14:14   #1 (permalink)
Punktruka está en el buen camino
 
Avatar de Punktruka
 
Fecha de Ingreso: enero-2005
Ubicación: Santiago, Chile
Mensajes: 207
Enviar un mensaje por MSN a Punktruka
Pregunta 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
__________________
y nada más
porke el cielo ya está de nuevo torvo y sin estrellas kon helikópteros y SIN DIOS....
Punktruka está desconectado   Responder Citando
Antiguo 14-jul-2005, 14:55   #2 (permalink)
Sir Matrix está en el buen camino
 
Avatar de Sir Matrix
 
Fecha de Ingreso: noviembre-2002
Ubicación: Dentro de mi cabeza. ono?
Mensajes: 1.248
Enviar un mensaje por ICQ a Sir Matrix
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
__________________
|||| ))>_<(( ||||
www.webmagic.cl <-- esta pagina está mala, no la busquen
Sir Matrix está desconectado   Responder Citando
Antiguo 14-jul-2005, 16:17   #3 (permalink)
Punktruka está en el buen camino
 
Avatar de Punktruka
 
Fecha de Ingreso: enero-2005
Ubicación: Santiago, Chile
Mensajes: 207
Enviar un mensaje por MSN a Punktruka
ok muuuuuuuuxaaas.. gracias por tu ayuda.
__________________
y nada más
porke el cielo ya está de nuevo torvo y sin estrellas kon helikópteros y SIN DIOS....
Punktruka está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 13:26.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93