MSAccessRookie
07-21-2008, 10:29 AM
I have a current Access query named FindProductsByBatchID that selects data based in user input (See Below). It seemed to me that the query could easily be replaced by an SQL Server User defined Function, so I created one. The SQL Server Management Studio accepts the function as properly formed when I execute the update, saying that the update succeeded. I cannot, however, get MS Access to recognize the function. Access indicates that there is a "Syntax error in FROM clause"
Below is my first attempt (based on a model from the Stored Procedure/Function Programming Book that I am currently reading). This is my first attempt at making a User defined Function here, so any advice is welcome.
-----------------------------------------------------------------------
Original Query:
SELECT BatchID, Product_ID, Amount, Unit, Price, InvoiceNumber, Institution, [Invoice Date]
FROM ViewMasterView
WHERE (BatchID Like "*" & [Type All or Part of BatchID] & "*");
NOTE: ViewMasterView is an SQL Server View that contains all data in the database that staisfies the query.
-----------------------------------------------------------------------
Proposed Function:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER FUNCTION FindProductsByBatchID
(
-- The parameters for the function are here
@TheBatchID nvarchar(50)
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT BatchID, Product_ID, Amount, Unit, Price, InvoiceNumber, Institution, [Invoice Date]
FROM dbo.ViewMasterView
WHERE (BatchID Like @TheBatchID)
)
GO
-----------------------------------------------------------------------
Access query to call the Function:
SELECT BatchID, Product_ID, Amount, Unit, Price, InvoiceNumber, Institution, [Invoice Date]
FROM dbo.FindProductsByBatchID("*" & [Type All or Part of BatchID] & "*");
-----------------------------------------------------------------------
Below is my first attempt (based on a model from the Stored Procedure/Function Programming Book that I am currently reading). This is my first attempt at making a User defined Function here, so any advice is welcome.
-----------------------------------------------------------------------
Original Query:
SELECT BatchID, Product_ID, Amount, Unit, Price, InvoiceNumber, Institution, [Invoice Date]
FROM ViewMasterView
WHERE (BatchID Like "*" & [Type All or Part of BatchID] & "*");
NOTE: ViewMasterView is an SQL Server View that contains all data in the database that staisfies the query.
-----------------------------------------------------------------------
Proposed Function:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER FUNCTION FindProductsByBatchID
(
-- The parameters for the function are here
@TheBatchID nvarchar(50)
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
SELECT BatchID, Product_ID, Amount, Unit, Price, InvoiceNumber, Institution, [Invoice Date]
FROM dbo.ViewMasterView
WHERE (BatchID Like @TheBatchID)
)
GO
-----------------------------------------------------------------------
Access query to call the Function:
SELECT BatchID, Product_ID, Amount, Unit, Price, InvoiceNumber, Institution, [Invoice Date]
FROM dbo.FindProductsByBatchID("*" & [Type All or Part of BatchID] & "*");
-----------------------------------------------------------------------