Hi everyone:
I am trying to ceate many tables on the fly with different names. I am using GUID,which I retrieved from another table as new tables names..code is as the following...but SQL keeps giving me syntax error, where @VariableName is being used...Can anyone please kindly take a look at my code and let me know what is wrong and what is the solution for it? Thanks alot
Declare CursorTable Cursor
Global
Static
for
Select [Lookup ID] ---GUID
from [Detail Name Lookup]
declare @TableName varchar(50)
Open CursorTable
Fetch next from CursorTable into @TableName
while @@Fetch_status = 0
begin
create table @TableName
(
[PK Run Detail] bigint identity(1,1) primary key not null,
[FK Run Analyses] uniqueidentifier default newid() not null,
[Detail Name] varchar(300) not null,
[Detail NumData] float not null,
)
Fetch next from CursorTable into @TableName
end
deallocate CursorTable
I am trying to ceate many tables on the fly with different names. I am using GUID,which I retrieved from another table as new tables names..code is as the following...but SQL keeps giving me syntax error, where @VariableName is being used...Can anyone please kindly take a look at my code and let me know what is wrong and what is the solution for it? Thanks alot
Declare CursorTable Cursor
Global
Static
for
Select [Lookup ID] ---GUID
from [Detail Name Lookup]
declare @TableName varchar(50)
Open CursorTable
Fetch next from CursorTable into @TableName
while @@Fetch_status = 0
begin
create table @TableName
(
[PK Run Detail] bigint identity(1,1) primary key not null,
[FK Run Analyses] uniqueidentifier default newid() not null,
[Detail Name] varchar(300) not null,
[Detail NumData] float not null,
)
Fetch next from CursorTable into @TableName
end
deallocate CursorTable