Home All Groups Group Topic Archive Search About
Author
16 Mar 2006 7:39 PM
Bahman
Hello!

The SP does not take table names as variables. But it takes variables for
conditions, return values, and such.

I have different tables depending on the case. I could merge them just for
this purpose or create multiple SP. Otherwise, somehow I need to tell the SP
what table to select from, so the name needs to be a variable. Basically SP
would have to compile 'now' without knowing if the table exists 'later'. If
the table would not exist, then it would take a 'default' value. Is there a
way around this without having to merge tables?

Thank you very much!

-Bahman

Author
16 Mar 2006 7:40 PM
Alejandro Mesa
The Curse and Blessings of Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html


AMB

Show quote
"Bahman" wrote:

> Hello!
>
> The SP does not take table names as variables. But it takes variables for
> conditions, return values, and such.
>
> I have different tables depending on the case. I could merge them just for
> this purpose or create multiple SP. Otherwise, somehow I need to tell the SP
> what table to select from, so the name needs to be a variable. Basically SP
> would have to compile 'now' without knowing if the table exists 'later'. If
> the table would not exist, then it would take a 'default' value. Is there a
> way around this without having to merge tables?
>
> Thank you very much!
>
> -Bahman
Author
16 Mar 2006 8:19 PM
David Portas
"Bahman" <Bah***@discussions.microsoft.com> wrote in message
news:56F621D6-C05F-4AC4-A8CE-FC2B2466EFF0@microsoft.com...

> I could merge them just for
> this purpose or create multiple SP.

That's right. Why don't you?

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Author
16 Mar 2006 9:16 PM
Bahman
David,

Yes, I thought about that as well (thinking about it more clearly after the
post than before!). SP is very important. To have it go at tables referencing
them based on a string variable alone and then change their content or
structure is logistically not 100%, although it seems to be perfectly
possible per AMB. I will redo this in a different way.

-Bahman

Show quote
"David Portas" wrote:

> "Bahman" <Bah***@discussions.microsoft.com> wrote in message
> news:56F621D6-C05F-4AC4-A8CE-FC2B2466EFF0@microsoft.com...
>
> > I could merge them just for
> > this purpose or create multiple SP.
>
> That's right. Why don't you?
>
> --
> David Portas, SQL Server MVP
>
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
>
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
>
>

AddThis Social Bookmark Button