Advertisement
brunobola

Untitled

Mar 2nd, 2023
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.74 KB | None | 0 0
  1. CREATE VIEW V_TRI_AnaliseEstornoVendas
  2. WITH SCHEMABINDING
  3. AS
  4. SELECT cd.Id,
  5.        cd.TipoDoc,
  6.        cd.Serie,
  7.        cd.NumDoc,
  8.        cd3.TipoDoc AS 'TipodocEstorno',
  9.        cd3.Serie AS 'SerieEstorno',
  10.        cd3.NumDoc AS 'NumDocEstorno',
  11.        cd3.DATA AS 'DataEstorno'
  12. FROM dbo.CabecDoc cd WITH (NOLOCK)
  13.     INNER JOIN  dbo.LinhasDoc ld WITH (NOLOCK)
  14.         ON ld.IdCabecDoc = cd.id
  15.     LEFT JOIN dbo.CabecDocStatus cs2 WITH (NOLOCK)
  16.         ON cs2.IdCabecDoc = cd.id
  17.     LEFT JOIN dbo.LinhasDoc ld3 WITH (NOLOCK)
  18.         ON ld3.IDLinhaEstorno = ld.Id
  19.     LEFT JOIN dbo.CabecDoc cd3 WITH (NOLOCK)
  20.         ON cd3.Id = ld3.IdCabecDoc
  21.     LEFT JOIN dbo.CabecDocStatus cs3 WITH (NOLOCK)
  22.         ON cs3.IdCabecDoc = cd3.Id
  23. WHERE
  24.     cd3.Id IS NOT NULL
  25. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement