Colm Kavanagh
2013-01-10 23:39:56 UTC
I am trying to convert my Access SQL queries into equivalent SQL server queries. However, SQL Server does not seem to like me using parameters. How can get around this problem? This is what I have now (@ContextDate is my date parameter):
SELECT dbo.[MIND Accounts].[Client-id], dbo.[MIND Accounts].[Client-name], SUM(dbo.Data.[Created transactions (number)]) AS [SumOfCreated transactions (number)]]],
SUM(dbo.Data.[Created refunds (number)]) AS [SumOfCreated refunds (number)],
SUM(dbo.Data.[Created transactions (value)] * dbo.[Currency conversion].[Conversion rate]) AS [Created transactions (EUR value)], dbo.Data.[Processing date]
FROM dbo.Data INNER JOIN
dbo.[Currency conversion] ON dbo.Data.Currency = dbo.[Currency conversion].Currency INNER JOIN
dbo.[MIND Accounts] ON dbo.Data.[Merchant CID] = dbo.[MIND Accounts].[Account-id]
GROUP BY dbo.[MIND Accounts].[Client-id], dbo.[MIND Accounts].[Client-name], dbo.Data.[Processing date]
HAVING (dbo.Data.[Processing date] <= CONVERT(DATETIME, @ContextDate, 102)) AND (dbo.Data.[Processing date] >= DATEADD(d, - 27, CONVERT(DATETIME, @ContextDate, 102)))
SELECT dbo.[MIND Accounts].[Client-id], dbo.[MIND Accounts].[Client-name], SUM(dbo.Data.[Created transactions (number)]) AS [SumOfCreated transactions (number)]]],
SUM(dbo.Data.[Created refunds (number)]) AS [SumOfCreated refunds (number)],
SUM(dbo.Data.[Created transactions (value)] * dbo.[Currency conversion].[Conversion rate]) AS [Created transactions (EUR value)], dbo.Data.[Processing date]
FROM dbo.Data INNER JOIN
dbo.[Currency conversion] ON dbo.Data.Currency = dbo.[Currency conversion].Currency INNER JOIN
dbo.[MIND Accounts] ON dbo.Data.[Merchant CID] = dbo.[MIND Accounts].[Account-id]
GROUP BY dbo.[MIND Accounts].[Client-id], dbo.[MIND Accounts].[Client-name], dbo.Data.[Processing date]
HAVING (dbo.Data.[Processing date] <= CONVERT(DATETIME, @ContextDate, 102)) AND (dbo.Data.[Processing date] >= DATEADD(d, - 27, CONVERT(DATETIME, @ContextDate, 102)))