Solved

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

Posted on 2004-08-16
13
224 Views
Last Modified: 2008-02-26
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
Comment
Question by:Suburb-Man
13 Comments
 
LVL 1

Author Comment

by:Suburb-Man
ID: 11817644
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
 
LVL 1

Author Comment

by:Suburb-Man
ID: 11817771
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
 
LVL 1

Author Comment

by:Suburb-Man
ID: 11817825
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
 
LVL 1

Author Comment

by:Suburb-Man
ID: 11817882
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 11818300
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
 
LVL 1

Author Comment

by:Suburb-Man
ID: 11823937
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:kselvia
ID: 11824026
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
 
LVL 12

Expert Comment

by:kselvia
ID: 11824061
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
 
LVL 1

Author Comment

by:Suburb-Man
ID: 11825665
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
 
LVL 1

Author Comment

by:Suburb-Man
ID: 11826918
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
 
LVL 1

Author Comment

by:Suburb-Man
ID: 12119294
I will try to post a conclusion this week.
I had to switch to different project....Security.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 12142682
Submitted to PAQ with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now