dynamic table name in sql
dynamic table name in sql
dynamic table name in sql
dynamic table name in sql
dynamic table name in sql
dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql
dynamic table name in sql dynamic table name in sql
dynamic table name in sql
Go Back  Xtreme Visual Basic Talk > > > dynamic table name in sql


Reply
 
Thread Tools Display Modes
  #1  
Old 09-19-2006, 01:33 PM
Beckett Beckett is offline
Regular
 
Join Date: Apr 2005
Location: Frisco, TX
Posts: 83
Default dynamic table name in sql


Hello,

I am trying to create a sql table with a variable for the name and then insert values I've selected from another table into the variable name table. I can create the table ok but am having trouble with the "INSERT INTO" part.

declare @ID nvarchar(10)
set @ID = 'xyz'

EXEC('CREATE TABLE ' + @ID + '(question nvarchar(10), orderby int)')
EXEC('insert into' + @ID + '(question, orderby)
select question, orderby from zrolestest')
GO

here is the error message I get - it's looking for the table with "into" at the beginning of the name instead of just a table called xyz:

Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'intoxyz'.
Reply With Quote
  #2  
Old 09-19-2006, 01:37 PM
00100b's Avatar
00100bdynamic table name in sql 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

You are missing a space.
Code:
EXEC('insert into' + @ID + '(question, orderby)
-- Should be
EXEC('insert into ' + @ID + '(question, orderby)
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #3  
Old 09-19-2006, 01:51 PM
Beckett Beckett is offline
Regular
 
Join Date: Apr 2005
Location: Frisco, TX
Posts: 83
Default

That fixed it -- thank you so much.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
dynamic table name in sql
dynamic table name in sql
dynamic table name in sql dynamic table name in sql
dynamic table name in sql
dynamic table name in sql
dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql dynamic table name in sql
dynamic table name in sql
dynamic table name in sql
 
dynamic table name in sql
dynamic table name in sql
 
-->