Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dinamic table update, pls help

Status
Not open for further replies.

victorashi

IS-IT--Management
Jul 22, 2006
32
0
0
RO
i need to update a table that i select dinamicaly
at update i need to acces the table's columns and asign eash a variable. here i'm stuck because i don't know how many columns the tables has, their names, and the variables i need to insert in them

-- if @a is the table that i imput

exec ('update '+@a' set --in this set i must acces the table's columns and asign each a variable

--i can make a query to give me the table's columns, like this:

select * from information_schema.columns where table_name =@a


but i still neet to put variables in the columns.
can u help me pls with thui dinamic update?
 
For starters, I hope you had your coffee this morning, cause this one will probably hurt.

If you actually want to do this your going to need to create a table with a column for Table.col_name and a col for program-variable. then you will have to select the table-col_name and program variables where table name = "Your Table"

Thats a start. If thats too much effort, you're best bet is to write out your SQL statements like most other people.

SWM Programmer Seeking 3d Modeling work. Either for long term commitment or just friendship. Likes long hours in front of a flat screen with heavy doses of Mountain Dew.
 
can u please be a little more specific?
i have to create a procedure that accepts a table name (for ex my_table) and creates a new table with two columns: a column with column names of my_table and a column with program variables.
(not sure i can make it, but...)
then how do i asign to my_table's columns the program variables?
 
you have to write scripting to read the col names and the variable names and then fill in the blanks, its going to be a royal PITA, but it might be cool when your done.

table:
col_1 col_2
name strMyName
addr strMyAddress


you have to fill in the reference table by hand and write code to read the col names and then build the sql statement with the variables in the right spot.

Unless this is a class project (which is forbidden here), or your boss is insane, your better off just writing multi SQL statements.

SWM Programmer Seeking 3d Modeling work. Either for long term commitment or just friendship. Likes long hours in front of a flat screen with heavy doses of Mountain Dew.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top