Hi Tim
I tried a few different ways but all are prompted with errors:
Example 1:
DECLARE @tablename varchar(30)
SELECT @tablename = 'hi'
CREATE TABLE @tablename (column_1 int)
Error: Incorrect syntax near '@tablename'.
Example 2:
DECLARE @tablename varchar(30)
DECLARE @sql varchar(200)...
Hi there
Is there any way to create a table in a stored procedure dynamically where the table name is based on a variable?
I did something as follows but it does not work.
Declare @sql varchar(255)
Declare @table_name varchar(30)
Select @table_name = 'my_table_01_2001'
Select @sql = 'create...
Hi there
Is there any way to check a table's existence before its creation in one stored procedure?? I did something as follows but it does not work. Please help me ...
Declare @sql varchar(255)
Select @sql = 'create table test (column_1 int primary key)
If (Exec @sql) <> 0
print 'Failed'...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.