Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-16
13
Medium Priority
?
291 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

927 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