Solved

Stored Procedure Help!

Posted on 2004-08-24
4
242 Views
Last Modified: 2008-03-06
Ok, here's a doozy, that I don't know if anybody has encountered:

I have this T-SQL script:

DECLARE @results varchar(1024)
EXEC ids_to_names @id_list = '34, 35, 36', @results = ''
SELECT @results

What it does is take those numbers(34,35,36) and convert them to what their foreign key dictates.  It returns something like this :  Active Member, Passive Member, Non-Member.  

Here's the problem:  When I execute this is the SQL Query Analyzer, it works all hunky-dory.

When I try and execute this from an ASP page using this script:

<!--#include virtual="/connections/connection.asp"-->
<%
set rs = my_Conn.execute("DECLARE @results varchar(1024) EXEC ids_to_names @id_list = '34, 35, 36', @results = '' SELECT @results")
if not rs.eof then
  response.write rs(0)
else
  response.write "EOF"
end if
set rs = Nothing
%>

I get this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e37'

[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'ttemp'.

/common/sp_test.asp, line 3

But I don't get this error when I run it in the SQL Query Analyzer....weird.

NOTE: I DO create a temporary table called 'ttemp'...use it, then drop it...however, when I reload this page, it says "Table already exists"...I'm at a loss...

Any help would be greatly appreciated (and subsequently awarded :P)

PS:  Here's the SP:

ALTER PROCEDURE ids_to_names (
    @id_list    varchar(32),@results  varchar(1024)
)
AS
    DECLARE @query varchar(256), @name VARCHAR(32)
    SET @query = 'SELECT [membership types].[membership type english] INTO ttemp FROM [Membership types] WHERE [membership type id] IN (' + @id_list + ')'
    EXEC( @query )
    DECLARE temp_cursor CURSOR FOR
    SELECT ttemp.[membership type english] FROM ttemp
    OPEN temp_cursor
    FETCH NEXT FROM temp_cursor INTO @name
    WHILE @@FETCH_STATUS = 0
        BEGIN
        IF @results = ''
            SET @results = @name
        ELSE
            SET @results = @results + ', ' + @name
        FETCH NEXT FROM temp_cursor INTO @name
        END
    CLOSE temp_cursor
    DEALLOCATE temp_cursor
    DROP TABLE ttemp
    SELECT @results

Cheers,

Dan


0
Comment
Question by:dwaldner
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
darksinclair earned 500 total points
ID: 11884738
0
 
LVL 5

Expert Comment

by:darksinclair
ID: 11884760
oh, and I have had this error before and that fixed me up.  

Cheers,
0
 
LVL 3

Author Comment

by:dwaldner
ID: 11884801
I'm running off of SQL Server 7.0 (shrug) :(
0
 
LVL 3

Author Comment

by:dwaldner
ID: 11884866
BRILLIANT!!!  It didn't like the idea of a certain type of temp table!  Thanks a bunch!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

19 Experts available now in Live!

Get 1:1 Help Now