
    Fai>                         S r SrSrSrSrSrg)zSELECT 1 AS ok;z
SELECT DISTINCT
    LTRIM(RTRIM(s.NombreSucursal)) AS NombreSucursal
FROM dbo.AA_Sucursales s
WHERE s.NombreSucursal IS NOT NULL
ORDER BY LTRIM(RTRIM(s.NombreSucursal));
ze
SELECT 
    MIN([Fecha]) AS fecha_min,
    MAX([Fecha]) AS fecha_max
FROM dbo.[RE_RemisionesLinea];
a  
SELECT
    v.Folio,
    v.Estacion,
    MIN(v.Fecha)       AS Fecha,
    MIN(v.HoraCaptura) AS HoraCaptura,
    SUM(CAST(v.Cant AS DECIMAL(18,4)) * CAST(v.PU AS DECIMAL(18,4))) AS ventas_subtotal,

    MIN(v.[Desc])      AS [Desc],
    MIN(v.Impto)       AS Impto,
    MIN(v.ImptoAdic)   AS ImptoAdic,
    MIN(v.Comision)    AS Comision,
    MIN(v.MotivoDev)   AS MotivoDev,

    MAX(s.NombreSucursal) AS NombreSucursal,
    MAX(s.Zona)           AS Zona,
    MAX(s.Ciudad)         AS Ciudad,
    MAX(s.Estado)         AS Estado
FROM dbo.RE_RemisionesLinea v
LEFT JOIN dbo.AA_EstacionesSucursal es ON es.Estacion = v.Estacion
LEFT JOIN dbo.AA_Sucursales s ON s.Sucursal = es.Sucursal
WHERE v.Fecha >= ? AND v.Fecha < ?
GROUP BY v.Folio, v.Estacion
a!  
SELECT
    v.Folio,
    v.Estacion,
    v.Fecha,
    v.HoraCaptura,
    CAST(v.Cant AS DECIMAL(18,4)) AS Cant,
    CAST(v.PU   AS DECIMAL(18,4)) AS PU,

    v.Cod,
    p.Descripcion AS Platillo,
    p.Clasif      AS Clasif,
    c.Descripcion AS Clasificacion_Platillo,

    v.[Desc],
    v.Impto,
    v.ImptoAdic,
    v.Comision,
    v.MotivoDev,

    LTRIM(RTRIM(s.NombreSucursal)) AS NombreSucursal
FROM dbo.RE_RemisionesLinea v
LEFT JOIN dbo.RE_Platillos p
    ON p.Cod = v.Cod
LEFT JOIN dbo.RE_Clasificacion c
    ON RIGHT('000' + LTRIM(RTRIM(p.Clasif)), 3) = RIGHT('000' + LTRIM(RTRIM(c.Clasif)), 3)
LEFT JOIN dbo.AA_EstacionesSucursal es
    ON es.Estacion = v.Estacion
LEFT JOIN dbo.AA_Sucursales s
    ON s.Sucursal = es.Sucursal
WHERE v.Fecha >= ? AND v.Fecha < ?
ORDER BY v.Fecha, v.Folio;
a  
SELECT
    v.Folio,
    v.Estacion,
    v.Fecha,
    v.HoraCaptura,
    CAST(v.Cant AS DECIMAL(18,4)) AS Cant,
    CAST(v.PU   AS DECIMAL(18,4)) AS PU,

    v.Cod,
    p.Descripcion AS Platillo,
    p.Clasif      AS Clasif,

    c.Descripcion AS Clasificacion_Platillo,

    v.[Desc],
    v.Impto,
    v.ImptoAdic,
    v.Comision,
    v.MotivoDev,

    s.NombreSucursal
FROM dbo.RE_RemisionesLinea v
LEFT JOIN dbo.RE_Platillos p
    ON p.Cod = v.Cod
LEFT JOIN dbo.RE_Clasificacion c
    ON RIGHT('000' + LTRIM(RTRIM(p.Clasif)), 3)
     = RIGHT('000' + LTRIM(RTRIM(c.Clasif)), 3)
LEFT JOIN dbo.AA_EstacionesSucursal es
    ON es.Estacion = v.Estacion
LEFT JOIN dbo.AA_Sucursales s
    ON s.Sucursal = es.Sucursal
WHERE v.Fecha >= ? AND v.Fecha < ?
ORDER BY v.Fecha, v.Folio;
N)
QUERY_TESTQUERY_SUCURSALESQUERY_VENTAS_MINMAXQUERY_FOLIOS_AGGQUERY_LINEAS_SUCURSALQUERY_LINEAS     ]C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\Proyectos\cabanna-api\app\queries.py<module>r      s2   
   2  D"r	   