Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-16
13
Medium Priority
?
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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 143

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
 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

721 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