Ver Mensaje Individual
  #20 (permalink)  
Antiguo 30/10/2013, 17:37
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Sumar valores de varias columnas en Join

puedes encadenar varios cases en uno solo

select case when 1=1 then else yo
when 2=2 then tu
when 3=3 then el else otro end


Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. dato VARCHAR(20)
  4. )
  5.  
  6. INSERT INTO #temp VALUES ('yo')
  7. INSERT INTO #temp VALUES ('tu')
  8. INSERT INTO #temp VALUES ('el')
  9. INSERT INTO #temp VALUES ('nos')
  10. INSERT INTO #temp VALUES ('yo')
  11.  
  12. SELECT CASE WHEN dato='yo' THEN 1
  13. WHEN dato='tu' THEN 2
  14. WHEN dato='el' THEN 3 ELSE 4 END AS columna,dato
  15. FROM #temp
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me