Solved

Stored Procedure Help!

Posted on 2004-08-24
4
248 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
[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
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

631 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