|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am pretty inexperienced when it comes to sql, but I am an experienced engineer.
Want to create a stored procedure. Within that procedure I am going to create a temp table with certain attributes read in from 2 other permanent tables. After that, within the stored procedure, I want to read the resulting rows of the temp table one by one (one of the attributes will be a key that I will use to access yet another permanent table). I dont know how to do this. select key1, att1 into #temp_table from permTable1 where key > xx date > 999999 insert #temp_table select key1, att1 from permTable1History where key > xx date > 999999 ....this is where I am stuck....how do I now read the contents of the #temp_table within the stored procedure one by one, to pull out that key attribute, to use to read from another permanent table? thanks, Bill |
|
#2
|
|||
|
|||
|
selecting with a temp table?
Here are some ideas, assuming I am understanding your needs right.
1. Use UNION instead of combining in a temp table. This can also be placed in a view any stored procedures can access. Code:
SELECT key1, att1 FROM permTable1 WHERE key > xx AND date > 999999 UNION ALL SELECT key1, att1 FROM permTable1History WHERE key > xx AND date > 999999 3. Instead of #temp_table use 2 "#"s, (##temp_table) so it's accessible from outside procedures (use with caution) Code:
select key1, att1 into ##temp_table from permTable1 where key > xx date > 999999 insert ##temp_table select key1, att1 from permTable1History where key > xx date > 999999 Code:
-- populate temp table EXEC sproc_make_temp_table -- select values (or process as necessary) SELECT key1, att1 FROM ##temp_table -- clean up table or it will stay there and can make a mess DROP TABLE ##temp_table |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Temp table manipulation in Stored Procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|