Skip to main content
se añadieron 80 caracteres en el cuerpo
Origen Enlace
J. Rodríguez
  • 5.3k
  • 6
  • 40
  • 77

(select t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2 from( SELECT
row_number() over (partition by decodigo,datepart(month,CAFECDOC) order by CAFECDOC desc, CATIPMOV desc ,CACODMOV desc,CAALMA desc,CATD desc,CANUMDOC desc,DEITEM desc)[Fila], DECODIGO as ACODIGO,DEDESCRI as ADESCRI,DEUNIDAD as AUNIDAD, (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) -1 then cast(DEPRECIO as money) else 0 end) Linea, (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) then cast(DEPRECIO as money) else 0 end) Linea2 from [025BDCOMUN].DBO.MOVALMCAB AS B INNER JOIN (MOVALMDET AS A LEFT JOIN MAEART AS M ON A.DECODIGO = M.ACODIGO) ON B.CAALMA = A.DEALMA AND B.CATD = A.DETD AND B.CANUMDOC = A.DENUMDOC WHERE
YEAR(CAFECDOC) = '2020' AND CASITGUI <> 'A' AND NOT (CATD = 'GS' AND CACODMOV = 'GF' AND CASITGUI = 'F') AND NOT (M.AFSTOCK = 'N' AND M.AFSERIE = 'N' AND M.AFLOTE = 'N') AND DECODIGO like '100%' AND (DECODIGO <> 'TEXTO') AND M.AFAMILIA >= '001' AND M.AFAMILIA <= '027') t1 where [Fila]=1 group by [Fila],t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2) order by ACODIGO

(select t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2 from(
            SELECT  
              row_number() over (partition by decodigo,datepart(month,CAFECDOC) order by CAFECDOC desc, CATIPMOV desc ,CACODMOV desc,CAALMA desc,CATD desc,CANUMDOC desc,DEITEM desc)[Fila],
              DECODIGO as ACODIGO,DEDESCRI as ADESCRI,DEUNIDAD as AUNIDAD,
             (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) -1  then cast(DEPRECIO as money)  else 0 end) Linea,
             (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) then cast(DEPRECIO as money)  else 0 end) Linea2
             from
             [025BDCOMUN].DBO.MOVALMCAB AS B INNER JOIN (MOVALMDET AS A 
                     LEFT JOIN MAEART AS M ON A.DECODIGO = M.ACODIGO) ON B.CAALMA = A.DEALMA AND B.CATD = A.DETD AND B.CANUMDOC = A.DENUMDOC
                     WHERE  
         YEAR(CAFECDOC) = '2020' AND 
       CASITGUI <> 'A' AND 
       NOT (CATD = 'GS' AND CACODMOV = 'GF' AND CASITGUI = 'F') AND 
       NOT (M.AFSTOCK = 'N' AND M.AFSERIE = 'N' AND M.AFLOTE = 'N') 
      AND DECODIGO like '100%' 
      AND (DECODIGO <> 'TEXTO')
      AND M.AFAMILIA >= '001' AND M.AFAMILIA <= '027') t1
            where [Fila]=1 
            group by [Fila],t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2)
            order by ACODIGO

(select t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2 from( SELECT
row_number() over (partition by decodigo,datepart(month,CAFECDOC) order by CAFECDOC desc, CATIPMOV desc ,CACODMOV desc,CAALMA desc,CATD desc,CANUMDOC desc,DEITEM desc)[Fila], DECODIGO as ACODIGO,DEDESCRI as ADESCRI,DEUNIDAD as AUNIDAD, (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) -1 then cast(DEPRECIO as money) else 0 end) Linea, (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) then cast(DEPRECIO as money) else 0 end) Linea2 from [025BDCOMUN].DBO.MOVALMCAB AS B INNER JOIN (MOVALMDET AS A LEFT JOIN MAEART AS M ON A.DECODIGO = M.ACODIGO) ON B.CAALMA = A.DEALMA AND B.CATD = A.DETD AND B.CANUMDOC = A.DENUMDOC WHERE
YEAR(CAFECDOC) = '2020' AND CASITGUI <> 'A' AND NOT (CATD = 'GS' AND CACODMOV = 'GF' AND CASITGUI = 'F') AND NOT (M.AFSTOCK = 'N' AND M.AFSERIE = 'N' AND M.AFLOTE = 'N') AND DECODIGO like '100%' AND (DECODIGO <> 'TEXTO') AND M.AFAMILIA >= '001' AND M.AFAMILIA <= '027') t1 where [Fila]=1 group by [Fila],t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2) order by ACODIGO

(select t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2 from(
            SELECT  
              row_number() over (partition by decodigo,datepart(month,CAFECDOC) order by CAFECDOC desc, CATIPMOV desc ,CACODMOV desc,CAALMA desc,CATD desc,CANUMDOC desc,DEITEM desc)[Fila],
              DECODIGO as ACODIGO,DEDESCRI as ADESCRI,DEUNIDAD as AUNIDAD,
             (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) -1  then cast(DEPRECIO as money)  else 0 end) Linea,
             (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) then cast(DEPRECIO as money)  else 0 end) Linea2
             from
             [025BDCOMUN].DBO.MOVALMCAB AS B INNER JOIN (MOVALMDET AS A 
                     LEFT JOIN MAEART AS M ON A.DECODIGO = M.ACODIGO) ON B.CAALMA = A.DEALMA AND B.CATD = A.DETD AND B.CANUMDOC = A.DENUMDOC
                     WHERE  
         YEAR(CAFECDOC) = '2020' AND 
       CASITGUI <> 'A' AND 
       NOT (CATD = 'GS' AND CACODMOV = 'GF' AND CASITGUI = 'F') AND 
       NOT (M.AFSTOCK = 'N' AND M.AFSERIE = 'N' AND M.AFLOTE = 'N') 
      AND DECODIGO like '100%' 
      AND (DECODIGO <> 'TEXTO')
      AND M.AFAMILIA >= '001' AND M.AFAMILIA <= '027') t1
            where [Fila]=1 
            group by [Fila],t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2)
            order by ACODIGO
Origen Enlace

SQL- Como puedo agrupar datos repetidos en una sola fila segun este codigo?

(select t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2 from( SELECT
row_number() over (partition by decodigo,datepart(month,CAFECDOC) order by CAFECDOC desc, CATIPMOV desc ,CACODMOV desc,CAALMA desc,CATD desc,CANUMDOC desc,DEITEM desc)[Fila], DECODIGO as ACODIGO,DEDESCRI as ADESCRI,DEUNIDAD as AUNIDAD, (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) -1 then cast(DEPRECIO as money) else 0 end) Linea, (case when DATEPART(month, CAFECDOC)=MONTH(GETDATE()) then cast(DEPRECIO as money) else 0 end) Linea2 from [025BDCOMUN].DBO.MOVALMCAB AS B INNER JOIN (MOVALMDET AS A LEFT JOIN MAEART AS M ON A.DECODIGO = M.ACODIGO) ON B.CAALMA = A.DEALMA AND B.CATD = A.DETD AND B.CANUMDOC = A.DENUMDOC WHERE
YEAR(CAFECDOC) = '2020' AND CASITGUI <> 'A' AND NOT (CATD = 'GS' AND CACODMOV = 'GF' AND CASITGUI = 'F') AND NOT (M.AFSTOCK = 'N' AND M.AFSERIE = 'N' AND M.AFLOTE = 'N') AND DECODIGO like '100%' AND (DECODIGO <> 'TEXTO') AND M.AFAMILIA >= '001' AND M.AFAMILIA <= '027') t1 where [Fila]=1 group by [Fila],t1.ACODIGO,t1.ADESCRI,t1.AUNIDAD,t1.Linea,t1.Linea2) order by ACODIGO

ME SALE ESTE RESULTADO

introducir la descripción de la imagen aquí

PERO INTENTE DE MUCHAS FORMAS Y NO ME SALE DE ESTA MANERA

introducir la descripción de la imagen aquí

LA UNICA SOLUCION QUE ENCONTRE FUE AGRUPARLO EN REPORTVIEWER PERO QUISIERA QUE ME SALGA EN SQL PORFAS.