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 |
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-02-22 : 09:02:59
|
| declare @pre_franchises table( class char(20))insert into @pre_franchisesselect 'blimp' union allselect 'subway' union allselect 'quizno' union allselect 'ponderosa' union allselect 'quincy'select * into #franchisesfrom @pre_franchisesIf I add one more string into @pre_franchise and rerun this piece of code I got errorerver: Msg 2714, Level 16, State 6, Line 11There is already an object named '#franchises' in the database.How can I solve this problem? (I only have select right to the database)Thanks. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-22 : 09:07:55
|
| The table #Franchises and @Franchises are not the same table.You have to DROP the table #Franchises first.This is not common in production stored procedures, this mostly happens in Query Analyzer and SSMS when running the code twice or more.Peter LarssonHelsingborg, Sweden |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-02-22 : 09:09:00
|
| select * into #franchisesfrom @pre_franchisesyou need toDROP TABLE #franchisesbefore you can do this a second time.Or you shouldINSERT into #franchisesselect * from @pre_franchisesfor subsequent uses(You may want toDELETE #franchisesfirst to "empty" the Temp tableNOTE that it would be better to CREATE #franchises before using it, rather than using "SELECT ... INTO #franchises" because that will potentially hold a lock on TEMPDB for extended periods.Kristen |
 |
|
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-02-22 : 09:19:09
|
| Thank you very much for your help |
 |
|
|
|
|
|