Phil Sowden (philsowden@dataservicesltd.co.uk) writes:[color=blue]
> I'd really appreciate your help creating a parameterised view in SQL
> Server, which I can then invoke from VB5. I'm using DAO and ODBC to
> connect to SQL Server 2000.
>
> I can open Tables and Views, but can't find how to create or use a
> "query" parameter. If I use the "?" (in the SQL Enterprise manager
> View design mode), the syntax checker verifies the query ok, but I
> then get the message "Parameters cannot be used in this query type".
> It doesn't like the %var% terminology at all here.
>
> I am sure I could build the full query in VB and save it to the Server
> "on-the-fly", but this partly defeats the object, doesn't it?
>
> I could really do with a couple of pointers: (a) how to define the
> view/query in Ent Manager and (b) how to invoke it from VB, supplying
> the parameter.[/color]
Views cannot be parameterized in SQL Server. However there are table-valued
functions, which are about the same thing. Example:
CREATE FUNCTION myorders (@custid nchar(5)) RETURNS TABLE AS
RETURN (SELECT * FROM Northwind..Orders WHERE CustomerID = @custid)
go
SELECT * FROM myorders(N'ALFKI')
--
Erland Sommarskog, SQL Server MVP,
sommar@algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp