Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2006, 09:03 AM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stored Procedures returning no results to access

Hi all,
need some help with stored procedures. I wrote a procedure with parameters which builds up a sql-statement in a variable. The last statement is "EXEC (SQL)". Via SQL Query Analyzer results will be shown. If I execute this procedure via Access I get a message like "stored procedure executed successfully but didn't return records". The SQL server I use is MS SQL version 7.

Do you have any idea resolving this problem?

Thx

Here's the coding of the stored procedure:

CREATE PROCEDURE dbo.spEDIMSucheSAPLaender
   @TOP integer,
   @LAND1 nvarchar(255),
   @INTCA nvarchar(255),
   @INTCA3 nvarchar(255),
   @LANDX nvarchar(255)
AS
   DECLARE @SQL varchar(8000)

   SET @SQL = 'SELECT * FROM tblSAPLaender WHERE 1=1'
   IF @LAND1 <> ''
      SET @SQL = @SQL + ' AND LAND1 LIKE ''' + @LAND1 + ''''

   IF @INTCA <> ''
      SET @SQL = @SQL + ' AND INTCA LIKE ''' + @INTCA + ''''

   IF @INTCA3 <> ''
      SET @SQL = @SQL + ' AND INTCA3 LIKE ''' + @INTCA3 + ''''

   IF @LANDX <> ''
      SET @SQL = @SQL + ' AND LANDX LIKE ''' + @LANDX + ''''

   IF @TOP <> ''
      SET @SQL = REPLACE(@SQL, 'SELECT', 'SELECT TOP ' +
         CONVERT(varchar(10),@Top))

   EXEC (@SQL)
GO
 
Old February 8th, 2006, 05:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

When you call from Query Analyzer- are you using the StoredProc or are you entering the actual SQL statement?

If your not using the SP then your not actually testing the SP.. you could have a problem with your building of the SQL statement-

I would return @SQL out of the SP, rather than execute it, and see if the statement that is built is what I expected.


Hal Levy
Please do your own homework.
I am here to help you, not do it for you.
I do not have sample code for anything
 
Old February 17th, 2006, 08:19 AM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same issue. SP runs as expected but no resutls returned.

My sp is migrating data between tables, has cursors in it and takes around 5 seconds to run. It has returned results once from access (when there was nothing to migrate and hence never looped the cursors) and it does work from access on other (much simpler) Sps.

Any ideas?

 
Old February 17th, 2006, 09:28 AM
Authorized User
 
Join Date: Oct 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try replacing
EXEC(SQL)

with EXEC SP_EXECUTESQL @SQL

and change the type of @SQL to 'nvarchar'
 
Old February 18th, 2006, 06:15 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

If you run a profiler trace on the calls that access makes to SQL Server you will typically see something like this
SET FMTOnly ON
EXEC yourproc
SET FTMOnly OFF
This asks your stored procedure to return just the framework of your result set (the metadata). Try running this in QA and see what you get.

Additionally, Access likes Procs that return only one result set, and one that is consistent (no if this then select 5 columns else select 4 columns). So remember to set nocount on in your procs and to have one result set returned.

David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
 
Old February 21st, 2006, 04:58 AM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Tried setting nocount on and it worked. Many thanks.

Strange thing is though it did work when I had no data. In that case the more complex selects inside my cursors and IFs would have been skipped, however it would still have run several selects throughout albeit much simpler ones.

Also tried FMTOnly ON and that did just return the framework, but I wasn't even getting that far in access. Will definately be checking out profiler in future though, thanks again.







Similar Threads
Thread Thread Starter Forum Replies Last Post
RecordSets vs Stored Procedures in Access Roy0 SQL Language 0 December 28th, 2005 02:02 PM
Returning Stored Procedure Results from ASP page JennaAckerson Classic ASP Basics 0 December 23rd, 2005 11:44 AM
Converting Access Queries Into Stored Procedures markw SQL Language 1 March 15th, 2005 11:49 AM
Access, SQL Server - Stored Procedures / DTS tcarnahan Access 5 September 1st, 2004 05:17 AM
stored procedures and MS Access madhukp Classic ASP Basics 5 August 26th, 2004 12:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.