Thursday, 15 April 2010

sql - Referring to a table by variable -



sql - Referring to a table by variable -

i'm sure pretty basic, how set insert statement using variable table name?

for example, have number of input files, configured identically (input1, input2, input3, ...) going insert or merge statement.

i want either loop, working through input files, or phone call insert statement function

insert [outputfile] select i.* [<input variable>] left bring together [outputfile] op on concat(i.field1, i.field6) = concat(op.field1, op.field6) op.field1 null print 'number of rows added ' + cast(@@rowcount char(6));

i'll using merge statements, assume process same.

how set insert statement using variable table name?

you don't, not straight sql. table names , column names cannot variables.

you can accomplish using dynamic sql, have careful not introduce sql injection.

the curse , blessings of dynamic sql fantastic in depth article discussing dynamic sql.

sql sql-server tsql sql-server-2012-express

No comments:

Post a Comment