Link to home
Start Free TrialLog in
Avatar of misdevelopers
misdevelopers

asked on

Read a Temp Table in a stored procedure

In sql server 2000.
I have a temp table in a stored procedure,
I want to read through the temp table and examine each column in each of the rows of that table.
How would I do that.
I also need to determine if the table is empty or not before I start reading it.

Thanks

Laurence

 
Avatar of rw3admin
rw3admin
Flag of United States of America image

You mean inside the proc? you can read the temp table just like regular table, you cannot reference this table outside the proc as Temp table is only local to the proc, actually local only to the session in which proc ran so you cannot say

select * from sMyProc.#TmpTable
Avatar of misdevelopers
misdevelopers

ASKER

Yes, I want to reference it inside the proc.
But I don't want to just create a recordset from the temp table.
I want to read through the temp table and examine each row and each column in each row.

I want to pass back just a few values from the recordset as OUPUT parameters,
rather than having to pass back the recordset (that was created from the temp table).

This is called thousands of times, for a report.

Laurence  
Avatar of Anthony Perkins
>>But I don't want to just create a recordset from the temp table.<<
The big question is: Why are you doing this?  This is the least efficient way of doing things using T-SQL.  However if you insist look up DECLARE CURSOR in BOL.
acperkins is right. Maybe you should try assigning the values required to variables using TSQL. That would be much faster. What would be the size of the temporary table? Is it necessary that you do it row-by-row and column-by-column? Maybe I can help if you ca explain what exactly you are looking for.
hi misdevelopers,
Read about table variables and functions inside books online may be that is what you are looking for.
ASKER CERTIFIED SOLUTION
Avatar of rw3admin
rw3admin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial