471,092 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

dynamically creating temp table names

Hello,
I am interested in dynamically creating temp tables using a
variable in MS SQL Server 2000.

For example:

DECLARE @l_personsUID int

select @l_personsUID = 9842

create table ##Test1table /*then the @l_personsUID */
(
resultset1 int
)

The key to the problem is that I want to use the variable
@l_personsUID to name then temp table. The name of the temp table
should be ##Test1table9842 not ##Test1table.

Thanks for you help.

Billy
Jul 20 '05 #1
5 15349

"Billy Cormic" <bi**********@hotmail.com> wrote in message
news:dd*************************@posting.google.co m...
Hello,
I am interested in dynamically creating temp tables using a
variable in MS SQL Server 2000.

For example:

DECLARE @l_personsUID int

select @l_personsUID = 9842

create table ##Test1table /*then the @l_personsUID */
(
resultset1 int
)

The key to the problem is that I want to use the variable
@l_personsUID to name then temp table. The name of the temp table
should be ##Test1table9842 not ##Test1table.

May I ask why?

You can probably do this by dynamically building the string.

But it's going to be messy.

Thanks for you help.

Billy

Jul 20 '05 #2
bi**********@hotmail.com (Billy Cormic) wrote in message news:<dd*************************@posting.google.c om>...
Hello,
I am interested in dynamically creating temp tables using a
variable in MS SQL Server 2000.

For example:

DECLARE @l_personsUID int

select @l_personsUID = 9842

create table ##Test1table /*then the @l_personsUID */
(
resultset1 int
)

The key to the problem is that I want to use the variable
@l_personsUID to name then temp table. The name of the temp table
should be ##Test1table9842 not ##Test1table.

Thanks for you help.

Billy


You could use dynamic SQL, but that would not be a good solution. If
the table names are dynamic, then all code accessing the tables would
need to be dynamic also, and that will create a lot of issues.

A better approach would be to have a single, permanent table, with
personsUID as part of the key. See here for a good discussion of this
issue:

http://www.algonet.se/~sommar/dynami...tml#Sales_yymm

Simon
Jul 20 '05 #3
I want to do this so that i can create individual tables to set as
datasources for certain crystal reports.

"Greg D. Moore \(Strider\)" <mo*****@greenms.com> wrote in message news:<2j********************@twister.nyroc.rr.com> ...
"Billy Cormic" <bi**********@hotmail.com> wrote in message
news:dd*************************@posting.google.co m...
Hello,
I am interested in dynamically creating temp tables using a
variable in MS SQL Server 2000.

For example:

DECLARE @l_personsUID int

select @l_personsUID = 9842

create table ##Test1table /*then the @l_personsUID */
(
resultset1 int
)

The key to the problem is that I want to use the variable
@l_personsUID to name then temp table. The name of the temp table
should be ##Test1table9842 not ##Test1table.


May I ask why?

You can probably do this by dynamically building the string.

But it's going to be messy.

Thanks for you help.

Billy

Jul 20 '05 #4
>> I am interested in dynamically creating temp tables using a
variable in MS SQL Server 2000. <<

Learn to write correct SQL instead. The use of temp tables is usually
a sign of really bad code -- the temp tables are almost always used to
hold steps in a procedural solution instead of a having a set-oriented
non-proceudral solution. This also says that you have no data model
and that any user, present or future, can change it on the fly.

Oh, if you don't care about performance, portability, readability,
security, and all that other stuff, then you can use dynamic SQL to
screw up your application this way.
Jul 20 '05 #5
OK. I will just create anohter table... not a bunch of temp tables to
hold the results.

thanks

jo*******@northface.edu (--CELKO--) wrote in message news:<a2**************************@posting.google. com>...
I am interested in dynamically creating temp tables using a

variable in MS SQL Server 2000. <<

Learn to write correct SQL instead. The use of temp tables is usually
a sign of really bad code -- the temp tables are almost always used to
hold steps in a procedural solution instead of a having a set-oriented
non-proceudral solution. This also says that you have no data model
and that any user, present or future, can change it on the fly.

Oh, if you don't care about performance, portability, readability,
security, and all that other stuff, then you can use dynamic SQL to
screw up your application this way.

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ex-Em-El | last post: by
7 posts views Thread by John Baker | last post: by
reply views Thread by Alexandre | last post: by
9 posts views Thread by netasp | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.