Hardwired
Hardwired

Reputation: 834

Select from tmp table in the stored proc

I'm trying to do the following:

  1. through the C++ code create a tmp table with a key/value columns and values (sybase db)

  2. create a sp in which I will do 'select * from #tmpTable'

  3. call this sp from the C++ code.

But I'm faced with a problem: I can't create the such stored proc. There is an error, that table doesn't exist (and it is so true).

So, can I do it in the some other way, or are there any tricks?

My sp example:

create procedure my_sp
as    
    begin
       if OBJECT_ID('#tmpTable') is not null   
           select key, value from '#tmpTable'
    end

Upvotes: 0

Views: 171

Answers (1)

Neeraj
Neeraj

Reputation: 316

You can create the temp as part of the same session when you compile the sp. This will allow sybase to compile your sp. You will need the tmp table definition for this. Try below -

use databasename
go

create table #tmpTable (key [keydatatype], value [valuedatatype], .....) 

create procedure my_sp
as    
    begin
       if OBJECT_ID('#tmpTable') is not null   
           select key, value from '#tmpTable'
    end

Upvotes: 1

Related Questions