Skip to content

Instantly share code, notes, and snippets.

@brunotdantas
Last active September 21, 2021 15:47
Show Gist options
  • Save brunotdantas/2f6589208bcfa470a8b4ef1b7711c920 to your computer and use it in GitHub Desktop.
Save brunotdantas/2f6589208bcfa470a8b4ef1b7711c920 to your computer and use it in GitHub Desktop.
[T-SQL] - PIVOT tabela dinâmica SQL T-SQL exemplo #SQL SERVER
USE INTEGRADOR
GO
SELECT Dia, [Linx Venda] as Linx,[Integ. Venda] as Integrador,[L1 Venda OK] as Protheus,
[Linx Venda]-[Integ. Venda] as 'Linx - Integrador',
[Integ. Venda]-[L1 Venda OK] as 'Integrador - Protheus',
[Linx Venda]-[L1 Venda OK] as 'Linx - Protheus'
FROM (select Dia, Origem, QtdDoc from [VW_ConsultaIntegracao] where Dia > GETDATE()-3) as consulta
Pivot
(
sum(QtdDoc)
for Origem in ([Integ. Venda],[Linx Venda],[L1 Venda OK])
)
as pivotconsulta
GO
Informação de referência: https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment