Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP 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 March 30th, 2005, 12:07 PM
Authorized User
 
Join Date: Sep 2004
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use Temp Table Variable in Stored Procedure

I'm playing with simple stored procedure with declared table variable as below:

Code:
CREATE PROCEDURE TEST
AS 
    Declare @myTable table
    (    
    Company varchar(10),
        Amount Money
    )
    INSERT INTO @myTable (Company, Amount)
    select company, amount from tblmonthly where company = '1234'
        select top 3  * from @mytable
return
GO
But when executing it with ADO in ASP page, it doesn't seem to return any data? Although I have no error with opening the recordset?

I use the following codes to do this:

Code:
        Set cmd = CreateObject("ADODB.Command")
        Set rs = CreateObject("ADODB.Recordset")
        cmd.ActiveConnection = adoCnn
        cmd.CommandText = "TEST"
        cmd.CommandType = adCmdStoredProc
        set rs = cmd.Execute

Is there any issue I need to take care of? It seems to have something to do with the table variable?
 
Old March 30th, 2005, 04:35 PM
Authorized User
 
Join Date: Sep 2004
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Answering my own question and for others who might benefit:

This is what I need to do, I added "SET NOCOUNT ON" in the beginning of the stored procedure to send back a closed recordset.

 
Old April 15th, 2011, 03:50 PM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default solution

I wrote a post about this a while ago - you essentially need to form the sql statement first by declaring a long varchar and then executing it.

http://www.geakeit.co.uk/2011/02/05/a-table-input-variable-in-a-stored-procedure-and-bypassing-must-declare-the-table-variable-msg-1087/





Similar Threads
Thread Thread Starter Forum Replies Last Post
store procedure, temp table kumiko SQL Language 2 January 15th, 2008 05:46 AM
Add new Table to Stored Procedure pallone SQL Server 2000 2 February 14th, 2007 12:58 PM
Stored Procedure That Updates Table GailCG Classic ASP Professional 1 January 22nd, 2006 01:11 PM
Passing Variable MS Proj to SQL Stored Procedure Abaxt Access VBA 2 July 7th, 2005 11:05 AM
Build a table from a Stored Procedure rogue248 SQL Server 2000 2 October 7th, 2004 10:06 PM





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