Skip to content

Instantly share code, notes, and snippets.

@bjcull
Created March 29, 2019 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjcull/4dee1d5b4b385bde48768a6699b12af9 to your computer and use it in GitHub Desktop.
Save bjcull/4dee1d5b4b385bde48768a6699b12af9 to your computer and use it in GitHub Desktop.
SQL Output for my perhaps not so efficient query
DECLARE @__submerchantId_0 int = 147;
DECLARE @__startDateLocal_Value_1 datetime2(7) = '2019-01-25';
DECLARE @__endDateLocal_Value_2 datetime2(7) = '2019-03-29';
DECLARE @__p_3 int = 0;
DECLARE @__p_4 int = 50;
SELECT [x.Payer].[Id], [x.Payer].[AssemblyBuyerId], [x.Payer].[CreatedTimeUtc], [x.Payer].[DisplayId], [x.Payer].[EmailAddress], [x.Payer].[FirstName], [x.Payer].[ImportSource], [x.Payer].[ImportSourceReference], [x.Payer].[IsDeleted], [x.Payer].[LastName], [x.Payer].[MobileNumber], [x.Payer].[Postcode], [x.Payer].[StreetAddress], [x.Payer].[SubMerchantId], [x.Payer].[Suburb], [x].[DisplayId] AS [Id0],
(
SELECT TOP(1) [y3].[Status]
FROM [Attempts] AS [y3]
WHERE ([y3].[IsDeleted] = 0) AND ([x].[Id] = [y3].[PaymentId])
ORDER BY [y3].[TransactionDateLocal] DESC
) AS [CurrentStatus], (
SELECT TOP(1) [y4].[Amount]
FROM [Attempts] AS [y4]
WHERE ([y4].[IsDeleted] = 0) AND ([x].[Id] = [y4].[PaymentId])
ORDER BY [y4].[TransactionDateLocal] DESC
) AS [Amount], (
SELECT TOP(1) [y5].[TransactionDateUtc]
FROM [Attempts] AS [y5]
WHERE ([y5].[IsDeleted] = 0) AND ([x].[Id] = [y5].[PaymentId])
ORDER BY [y5].[TransactionDateUtc] DESC
) AS [TransactionDateInternal], (
SELECT TOP(1) [y6].[EstimatedTransferDateLocal]
FROM [Attempts] AS [y6]
WHERE ([y6].[IsDeleted] = 0) AND ([x].[Id] = [y6].[PaymentId])
ORDER BY [y6].[TransactionDateLocal] DESC
) AS [EstimatedTransferDate], [x].[Description]
FROM [Payments] AS [x]
INNER JOIN [Payers] AS [x.Payer] ON [x].[PayerId] = [x.Payer].[Id]
WHERE (((([x.Payer].[SubMerchantId] = @__submerchantId_0) AND ((
SELECT TOP(1) [y].[Status]
FROM [Attempts] AS [y]
WHERE ([y].[IsDeleted] = 0) AND ([x].[Id] = [y].[PaymentId])
ORDER BY [y].[TransactionDateLocal] DESC
) <> 1)) AND ((
SELECT TOP(1) [y0].[TransactionDateLocal]
FROM [Attempts] AS [y0]
WHERE ([y0].[IsDeleted] = 0) AND ([x].[Id] = [y0].[PaymentId])
ORDER BY [y0].[TransactionDateLocal] DESC
) >= @__startDateLocal_Value_1)) AND ((
SELECT TOP(1) [y1].[TransactionDateLocal]
FROM [Attempts] AS [y1]
WHERE ([y1].[IsDeleted] = 0) AND ([x].[Id] = [y1].[PaymentId])
ORDER BY [y1].[TransactionDateLocal] DESC
) <= @__endDateLocal_Value_2)) AND ([x].[IsDeleted] = 0)
ORDER BY (
SELECT TOP(1) [y2].[TransactionDateLocal]
FROM [Attempts] AS [y2]
WHERE ([y2].[IsDeleted] = 0) AND ([x].[Id] = [y2].[PaymentId])
ORDER BY [y2].[TransactionDateLocal] DESC
) DESC
OFFSET @__p_3 ROWS FETCH NEXT @__p_4 ROWS ONLY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment