Solved

Stored Procedure Help!

Posted on 2004-08-24
4
246 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pass through dll 2 99
Html fieldset fix its height and width 4 44
Time comparison asp 1 21
MS SQL + date 6 42
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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