I have this SQL Query and i want the results in an Excel 2013 sheet / table
SELECT
[MS Part Number], [Item Name], SUM([Aantal]) AS Aantal, [Prijs]
FROM
(
SELECT
[MS Part Number], [Item Name], SUM([Aantal]) AS Aantal, [Prijs]
FROM
vwSPLAInformatie
WHERE
(DATEPART(YEAR, fakdat) = '2013')
AND (DATEPART(QUARTER, fakdat) = '1')
AND docnumber LIKE '%kwartaal%'
GROUP BY
[MS Part Number], [Item Name], [Aantal], [Prijs]
UNION ALL
SELECT
[MS Part Number], [Item Name], SUM([Aantal]) AS Aantal, [Prijs]
FROM
vwSPLAInformatie
WHERE
(DATEPART(YEAR, fakdat) = '2013')
AND (DATEPART(MONTH, fakdat) = '1')
AND NOT docnumber LIKE '%kwartaal%'
GROUP BY
[MS Part Number], [Item Name], [Aantal], [Prijs]
) AS Basis
GROUP BY
[MS Part Number], [Item Name], [Prijs]
It works perfectly, the only thing is that i have 4 parameters that i want to connect to 3 cell values in Excel. (Year = 2013) (Quarter = 1) (Month = 2). But when i adjust my Query to the following:
WHERE (DATEPART(YEAR, fakdat) = '?')
And i select the cell in Excel that says 2013, so basicly it should work, but it doensn't. I get the following error:
[Microsoft]ODBC SQL Server][SQL Server]Conversion failed when converting the varchar value '?' to data type in.
The value is the same, but it does not work at all. How can i fix this? I would be extremely happy when this works! In forward, many thanks.