Using Parameters

SQL Server stored procedures that have parameters need a different syntax from Access queries, for example:

Access 2.0:

Query Name: Employee Sales By Country, in NWIND.mdb:

PARAMETERS [Beginning Date] DateTime, [Ending Date] DateTime;

SELECT Orders.[Order ID], [Last Name] & ", " & [First Name] AS Salesperson, Employees.Country, Orders.[Shipped Date], [Order Subtotals].Subtotal AS [Sale Amount]

FROM Employees INNER JOIN (Orders INNER JOIN [Order Subtotals] ON Orders.[Order ID] = [Order Subtotals].[Order ID]) ON Employees.[Employee ID] = Orders.[Employee ID]

WHERE (((Orders.[Shipped Date]) Between [Beginning Date] And [Ending Date]))

ORDER BY [Last Name] & ", " & [First Name], Employees.Country, Orders.[Shipped Date];

  

SQL Server 7.0:

CREATE PROCEDURE EMP_SALES_BY_COUNTRY 

@BeginningDate datetime,

@EndingDate datetime

AS

SELECT Orders.[Order ID], [Last Name] + ", " + [First Name] AS Salesperson, Employees.Country, 

Orders.[Shipped Date], [Order Subtotals].Subtotal AS [Sale Amount]

FROM Employees INNER JOIN (Orders INNER JOIN [Order Subtotals] ON Orders.[Order ID] = [Order Subtotals].[Order ID]) ON Employees.[Employee ID] = Orders.[Employee ID]

WHERE (((Orders.[Shipped Date]) Between @BeginningDate And @EndingDate))

ORDER BY [Last Name] + ", " + [First Name], Employees.Country, Orders.[Shipped Date]

GO

  

For more information, see SQL Server Books Online.