Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a table his name from variable in SQL Server i use proc to create that by using C# call that by param but the syntax in SQL is wrong how can i do that , I tried


create table @temp
but I got an error

Incorrect syntax

Regards
Posted
Comments
[no name] 19-Jul-15 15:27pm    
http://www.w3schools.com/sql/sql_create_table.asp

1 solution

When creating a table the name of the table cannot be a variable. However what you can do is that you can build the SQL statement into a variable and then execute it.

Something like
SQL
DECLARE @sql NVARCHAR(MAX)
SET @sql = 'CREATE TABLE ' + @tablenamevariable
EXECUTE sp_executesql @stmt = @sql

For more information, see sp_executesql[^]
 
Share this answer
 
Comments
MASOUDOZ11 20-Jul-15 9:04am    
Thanks My dear

Regards
Wendelius 20-Jul-15 9:12am    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900