stored procedure help.

  • Thread starter Thread starter trialproduct2004
  • Start date Start date
T

trialproduct2004

Hi all

i am new to sql server.

i want to write stored procedure in sql server to insert values into
two table whose structure is same.

i have one condition depending on which i am inserting values into
either of this table

e.g insert into table1 values()...
instead of table1 i want to user variable name.

how can i use variable in insert query instead of exact table name.

can someone help me.

thanks in advance.
 
Hi all
i am new to sql server.

i want to write stored procedure in sql server to insert values into
two table whose structure is same.

i have one condition depending on which i am inserting values into
either of this table

e.g insert into table1 values()...
instead of table1 i want to user variable name.

how can i use variable in insert query instead of exact table name.

can someone help me.

thanks in advance.

You can't use variables instead of the table name.
One way would be to use "dynamic sql" (build a sql statement in a
string, and execute that).
But if you have just two tables, why not write it out:

if condition
insert into table1 ...
else
insert into table2

Easier to read and sp can be compiled (=faster).

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top