From: tshah on
Hello all,

I am trying to create a staging table using CREATE TABLE statement on a file
group with the file group name decided at the exectution time. Is there any
way, I can supply the file group name in the form of variable or using CTE
when I create the table using CREATE TABLE statement in a stored procedure or
in a SQL batch in SQL 2005?

If you happen to know, please show me how or direct me to the resource.

Thanks,

tshah
From: Razvan Socol on
tshah wrote:

> Hello all,
>
> I am trying to create a staging table using CREATE TABLE statement on a
> file group with the file group name decided at the exectution time. Is
> there any way, I can supply the file group name in the form of variable
> or using CTE when I create the table using CREATE TABLE statement in a
> stored procedure or in a SQL batch in SQL 2005?
>
> If you happen to know, please show me how or direct me to the resource.
>
> Thanks,
>
> tshah

You can use dynamic sql, like this:

DECLARE @fgname sysname, @sql nvarchar(max)
SET @fgname='PRIMARY'
SET @sql='CREATE TABLE tbl (x int) ON '+QUOTENAME(@fgname)
EXEC(@sql)

--
Razvan Socol
SQL Server MVP
From: tshah on
Thanks Razvan for your reply; it worked out for me.

Regards,

tshah.

"Razvan Socol" wrote:

> tshah wrote:
>
> > Hello all,
> >
> > I am trying to create a staging table using CREATE TABLE statement on a
> > file group with the file group name decided at the exectution time. Is
> > there any way, I can supply the file group name in the form of variable
> > or using CTE when I create the table using CREATE TABLE statement in a
> > stored procedure or in a SQL batch in SQL 2005?
> >
> > If you happen to know, please show me how or direct me to the resource.
> >
> > Thanks,
> >
> > tshah
>
> You can use dynamic sql, like this:
>
> DECLARE @fgname sysname, @sql nvarchar(max)
> SET @fgname='PRIMARY'
> SET @sql='CREATE TABLE tbl (x int) ON '+QUOTENAME(@fgname)
> EXEC(@sql)
>
> --
> Razvan Socol
> SQL Server MVP
>