Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
PFD401
Starting Member
2 Posts |
Posted - 2009-03-06 : 11:21:59
|
| I have hit a snag in development...When attempting to create a stored proc in which the user supplies variables that can be used to search out info from tables for the x and y axis of a table to be passed back to the user, I can't seem to manipulate the temp table (@ type, not #) the way I would like to. I can't seem to add columns, or rename them (or name them based on variables). Is there any way of creating a table in a stored procedure that defines the columns non-statically?Thanks |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-03-06 : 13:58:25
|
| You wouldn't be able to manipulate a table variable afterwards because they're stored in memory(except if you overflow) but you would be able to manipulate a temp table. You could create it with dynamic sql but doing so means you'd have to create a global temp table like this:declare @mysql nvarchar(200)select @mysql='create table ##temp(testing int)'exec sp_executesql @mysqlselect * from ##tempMike"oh, that monkey is going to pay" |
 |
|
|
PFD401
Starting Member
2 Posts |
Posted - 2009-03-06 : 14:33:05
|
| Can you work with the table after creating it (I assume so, just wanted to confirm).Like...declare @mysql nvarchar(200)select @mysql='create table ##temp(testing int)'exec sp_executesql @mysqlInsert into ##temp 123Insert into ##temp 654select * from ##tempIf so, I think this is the way to do it! Thanks! |
 |
|
|
|
|
|