[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

SQL2k Server User Defined Function A2k client report's Record Source

I create a report that uses a User Defined Function (UDF) as its "Record Source".
I develop with Access 2003 into an Access 2000 formatted database front-end.
The end users (clients) all have Access 2000, which doesn't see/find the SQL User Defined Functions.
The A2k clients get "record source "UDF Name" specified on this form or report does not exist!
This exact same Access 2000 formatted ADP works fine in Access 2003.

What do I do?

Here is the UDF's code:
CREATE PROCEDURE dbo.qCountReportBranchServices3(@StartDate datetime = '{ fn NOW() } - 31',
@EndDate datetime = '{ fn NOW() }',
@Branch varchar(20))
AS
RETURN ( SELECT     dbo.Clients.CustomerID + 1000 AS CID, dbo.Branch.Branch_Name,
                      ISNULL(dbo.Clients.ContactLastName, N'')
                      + N', ' + ISNULL(dbo.Clients.ContactFirstName, N'') + N' ' + ISNULL(dbo.Clients.C_MiddleName, N'') AS FullName, dbo.Clients.ContactFirstName,
                      dbo.Clients.ContactLastName, dbo.Clients.C_MiddleName, dbo.ServiceList.[NSCL-Date], dbo.ServiceList.ID AS Visit_ID, dbo.ServiceList.ReasonforVisit,
                      dbo.ServiceList.VisitNote
FROM         dbo.Clients LEFT OUTER JOIN
                      dbo.Branch ON dbo.Clients.Branch_ID = dbo.Branch.Branch_ID LEFT OUTER JOIN
                      dbo.ServiceList ON dbo.Clients.CustomerID = dbo.ServiceList.CustomerID
WHERE     (dbo.ServiceList.[NSCL-Date] >= @StartDate) AND (dbo.ServiceList.[NSCL-Date] <= @EndDate + 0.99999) AND
                      (dbo.Branch.Branch_Name LIKE ISNULL(@Branch, '') + '%') )
0
Suburb-Man
Asked:
Suburb-Man
1 Solution
 
Suburb-ManAuthor Commented:
I somewhat made a workaround by converting to stored procedure, however I would like to know if UDF are accessible to ACCESS 2000?

CREATE PROCEDURE dbo.spCountReportBranchServices3(@StartDate datetime = '{ fn NOW() } - 31',
@EndDate datetime = '{ fn NOW() }',
@Branch varchar(20))
AS
SELECT     dbo.Clients.CustomerID + 1000 AS CID, dbo.Branch.Branch_Name,
                      ISNULL(dbo.Clients.ContactLastName, N'')
                      + N', ' + ISNULL(dbo.Clients.ContactFirstName, N'') + N' ' + ISNULL(dbo.Clients.C_MiddleName, N'') AS FullName, dbo.Clients.ContactFirstName,
                      dbo.Clients.ContactLastName, dbo.Clients.C_MiddleName, dbo.ServiceList.[NSCL-Date], dbo.ServiceList.ID AS Visit_ID, dbo.ServiceList.ReasonforVisit,
                      dbo.ServiceList.VisitNote
FROM         dbo.Clients LEFT OUTER JOIN
                      dbo.Branch ON dbo.Clients.Branch_ID = dbo.Branch.Branch_ID LEFT OUTER JOIN
                      dbo.ServiceList ON dbo.Clients.CustomerID = dbo.ServiceList.CustomerID
WHERE     (dbo.ServiceList.[NSCL-Date] >= @StartDate) AND (dbo.ServiceList.[NSCL-Date] <= @EndDate + 0.99999) AND
                      (dbo.Branch.Branch_Name LIKE ISNULL(@Branch, '') + '%')



GO
0
 
Suburb-ManAuthor Commented:
Report will run once good, on second attempt I get:
"syntax error converting datetime from character string"
If I open the StoredProcedure and resave it, then the Report will work again, one time.
0
 
Suburb-ManAuthor Commented:
Tried adding, convert(DateTime,isnull(@StartDate,''))
But no good still error upon second run.

CREATE PROCEDURE dbo.spCountReportBranchServices3(@StartDate datetime = '{ fn NOW() } - 31',
@EndDate datetime = '{ fn NOW() }',
@Branch varchar(20))
AS SELECT     dbo.Clients.CustomerID + 1000 AS CID, dbo.Branch.Branch_Name, ISNULL(dbo.Clients.ContactLastName, N'')
                      + N', ' + ISNULL(dbo.Clients.ContactFirstName, N'') + N' ' + ISNULL(dbo.Clients.C_MiddleName, N'') AS FullName, dbo.Clients.ContactFirstName,
                      dbo.Clients.ContactLastName, dbo.Clients.C_MiddleName, dbo.ServiceList.[NSCL-Date], dbo.ServiceList.ID AS Visit_ID, dbo.ServiceList.ReasonforVisit,
                      dbo.ServiceList.VisitNote
FROM         dbo.Clients LEFT OUTER JOIN
                      dbo.Branch ON dbo.Clients.Branch_ID = dbo.Branch.Branch_ID LEFT OUTER JOIN
                      dbo.ServiceList ON dbo.Clients.CustomerID = dbo.ServiceList.CustomerID
WHERE     (dbo.ServiceList.[NSCL-Date] >= Convert(DateTime,isnull(@StartDate,''))) AND (dbo.ServiceList.[NSCL-Date] <= Convert(DateTime,isnull(@EndDate,''))) AND
                      (dbo.Branch.Branch_Name LIKE ISNULL(@Branch, '') + '%')
GO

HELP!
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
Suburb-ManAuthor Commented:
Access 2003 hides parameter properties ( you have to F4 or View > Properties.
The '{ fn NOW() }' was messing it up, so I changed it to literal values.

CREATE PROCEDURE dbo.spCountReportBranchServices3(@StartDate datetime = '2004-01-01 00:00:00',
@EndDate datetime = '2004-08-01 00:00:00',
@Branch varchar(20))

I still would like to know how to get Access 2000 to use UDF.
I found a ms article: SQL Server 2000 Resource Kit
Chapter 5 - Migrating Access 2000 Databases to SQL Server 2000
http://www.microsoft.com/resources/documentation/sql/2000/all/reskit/en-us/part2/c0561.mspx
But I couldn't get it to work.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Hi,
  I see, you are working hard on it :-)

  Ok, I created a user defined function in SQL Server 2000
  Then, I used the forms properties and set the record source to
  SELECT * FROM MyUserDefinedFunction()

  and this worked fine for A2k and A2k3

CHeers  
0
 
Suburb-ManAuthor Commented:
So since my procedure is "dbo.spCountReportBranchServices3"
I tried SELECT * FROM dbo.qCountReportBranchServices3() and
SELECT * FROM qCountReportBranchServices3()

I get an error: "insufficient number of arguments were supplied for the procedue of function"
The function is above in my original question.

Also the workaround SP I changed from embedded function "'{ fn NOW() }'" to static doesn't work for me because todays data is needed.  Access 2000 doesn't understand "GetDate()" and Access/SQL craps out after second run of "'{ fn NOW() }'".  It must be SQL optimizing the SP after it runs once. How can I tell SQL to leave the SP alone!
0
 
Ken SelviaRetiredCommented:
Functions can not reference getdate() but you can do this to get around it;

create view v_getdate as select getdate() vgetdate

Then join to this view in your function;

CREATE PROCEDURE dbo.spCountReportBranchServices3(@Branch varchar(20))
AS SELECT     dbo.Clients.CustomerID + 1000 AS CID, dbo.Branch.Branch_Name, ISNULL(dbo.Clients.ContactLastName, N'')
                      + N', ' + ISNULL(dbo.Clients.ContactFirstName, N'') + N' ' + ISNULL(dbo.Clients.C_MiddleName, N'') AS FullName, dbo.Clients.ContactFirstName,
                      dbo.Clients.ContactLastName, dbo.Clients.C_MiddleName, dbo.ServiceList.[NSCL-Date], dbo.ServiceList.ID AS Visit_ID, dbo.ServiceList.ReasonforVisit,
                      dbo.ServiceList.VisitNote

FROM    v_getdate,

                      dbo.Clients LEFT OUTER JOIN
                      dbo.Branch ON dbo.Clients.Branch_ID = dbo.Branch.Branch_ID LEFT OUTER JOIN
                      dbo.ServiceList ON dbo.Clients.CustomerID = dbo.ServiceList.CustomerID

WHERE     (dbo.ServiceList.[NSCL-Date] >= dateadd(dd,-31,vgetdate) ) AND (dbo.ServiceList.[NSCL-Date] <= vgetdate)

AND          (dbo.Branch.Branch_Name LIKE ISNULL(@Branch, '') + '%')
0
 
Ken SelviaRetiredCommented:
I just realized you are not really creating a function. That is a stored procedure. You should be able to use getdate() there without using Access' now().
0
 
Suburb-ManAuthor Commented:
The following SP code works, but only matches field values with just dates "1/1/2004"
not full datetime "1/1/2004 12:00:00", When just date is entered "1/1"
If a full Date and Time is entered in @Start and @End then all records are found.
Even though I added a convert to DateTime to all date fields.

Any ideas how to get it find all by just entering date "1/1", like Acess 2003 works with dbo.fxCountReportBranchServices3?

CREATE PROCEDURE dbo.spCountReportBranchServices3 @StartDate  datetime, @EndDate datetime, @Branch varchar(20)
AS
set nocount on

SELECT     dbo.Clients.CustomerID + 1000 AS CID, dbo.Branch.Branch_Name, ISNULL(dbo.Clients.ContactLastName, N'')
                      + N', ' + ISNULL(dbo.Clients.ContactFirstName, N'') + N' ' + ISNULL(dbo.Clients.C_MiddleName, N'') AS FullName, dbo.Clients.ContactFirstName,
                      dbo.Clients.ContactLastName, dbo.Clients.C_MiddleName, dbo.ServiceList.[NSCL-Date], dbo.ServiceList.ID AS Visit_ID, dbo.ServiceList.ReasonforVisit,
                      dbo.ServiceList.VisitNote
FROM         dbo.Clients LEFT OUTER JOIN
                      dbo.Branch ON dbo.Clients.Branch_ID = dbo.Branch.Branch_ID LEFT OUTER JOIN
                      dbo.ServiceList ON dbo.Clients.CustomerID = dbo.ServiceList.CustomerID
WHERE     (Convert(DateTime,isnull(dbo.ServiceList.[NSCL-Date],'')) >= Convert(DateTime,isnull(@StartDate,''))) AND (Convert(DateTime,isnull(dbo.ServiceList.[NSCL-Date],'')) <= Convert(DateTime,isnull(@EndDate,''))) AND
                      (dbo.Branch.Branch_Name LIKE ISNULL(@Branch, '') + '%')
GO

0
 
Suburb-ManAuthor Commented:
I modified the where statement:
WHERE     (Convert(DateTime,isnull(dbo.ServiceList.[NSCL-Date],'')) >= Convert(DateTime,isnull(@StartDate,'') AND (Convert(DateTime,isnull(dbo.ServiceList.[NSCL-Date],'')) <= Convert(DateTime,isnull(@EndDate,''))+'23:59:59') AND
                      (dbo.Branch.Branch_Name LIKE ISNULL(@Branch, '') + '%')

Now they just have to enter Month/Day.
0
 
Suburb-ManAuthor Commented:
I will try to post a conclusion this week.
I had to switch to different project....Security.
0
 
DarthModCommented:
Submitted to PAQ with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now