Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT with CASE
Message
 
 
To
21/02/2005 18:56:09
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00989053
Message ID:
00989087
Views:
20
This message has been marked as the solution to the initial question of the thread.
If you don't want group on d.n_ent_sai, why do you include it into column list and GROUP BY?
SELECT c_cod_art, c.c_descri, b.c_nome,
  c.n_ult_preco, c.n_ult_preco_liq, c.n_pcm,
  SUM (CASE WHEN d.n_ent_sai =  1 THEN n_quant_1 ELSE 0 END)  as ENT,	
  SUM (CASE WHEN d.n_ent_sai =  2 THEN n_quant_1 ELSE 0 END)  as SAI 	
  FROM tbl_gc_movimentosstk a
  LEFT outer join tbl_gc_Artigos c on c.c_codigo=a.c_cod_art
  LEFT join tbl_gc_codMovimentosStk d on d.c_codigo=a.c_cod_mov
  GROUP BY c_cod_art, c.c_descri, b.c_nome, c.n_ult_preco, c.n_ult_preco_liq, c.n_pcm
  ORDER BY c_cod_art,d.n_ent_sai
>Sorry Sergey, i remove some clause (my mistake), the full one,
>
>SELECT distinct  c_cod_art, c.c_descri, d.n_ent_sai, b.c_nome,
>  c.n_ult_preco, c.n_ult_preco_liq, c.n_pcm,
>  SUM (CASE WHEN d.n_ent_sai =  1 THEN n_quant_1 ELSE 0 END)  as ENT,	
>  SUM (CASE WHEN d.n_ent_sai =  2 THEN n_quant_1 ELSE 0 END)  as SAI 	
>  FROM tbl_gc_movimentosstk a
>  LEFT outer join tbl_gc_Artigos c on c.c_codigo=a.c_cod_art
>  LEFT join tbl_gc_codMovimentosStk d on d.c_codigo=a.c_cod_mov
>  GROUP BY c_cod_art, c.c_descri, d.n_ent_sai, b.c_nome, c.n_ult_preco,
>  c.n_ult_preco_liq, c.n_pcm
>  ORDER BY c_cod_art,d.n_ent_sai
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform