[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Global update of column based upon contents of another table

I need to update a table with a date field that is calculated from the contents of another table.

I have a table that stores ticks for a persons birthdate (demographics)

I want to be able to take the id and birthdate from the demographics table and update/insert into a second table with the
id = id
birthdate=datetime.frombinary(demographics.birthdate)

I've been able to create the connections to the tables but i have not been able to figure out how to just update the contents of a column based upon an expression withouth going through the records one by one.
Something like...
Do while .not. eof()
enter_begin(table2)
table2.id = table1.id
table2.birthdate = datetime.frombinary(table1.birthdate.tostring)
next
end while

I'm not much of a programmer and I was hoping vb 2008 would be easy but I appear to be hitting a big learning curve on "global" updates..
0
omagarc
Asked:
omagarc
  • 2
  • 2
1 Solution
 
JimFiveCommented:
Assuming that you are using a database to store your data you could just execute a pair of sql commands like:
UPDATE Table2 Set birthdate = (Select birthdate from table1 where Table2.id = table1id)

INSERT INTO TABLE2 (id, birthdate)
(Select id, birthdate from Table1 where Not exists (Select * from Table2 where table2.id = table1.id))
--
JimFive
0
 
omagarcAuthor Commented:
Thanks but I'm asking for code that I can put in a button that will loop through the table until it reaches the end
0
 
AUmidhCommented:

Buton Click Event.
{

Dim strFiter as String  ="Table2.id='" table1.id "'"
Dim dRows() as DataRow=ds.Tables(table2).Select(strFilter)
dim strBirthday as String=dRows(0)("Birthdate")

' Now you get strBirthDay make a query like

Dim strSQL as String ="UPDATE Table1 Set birthdate ='" + strBirthDay + "'"

' and using this strSQL you can update the Table2
}
0
 
AUmidhCommented:

Buton Click Event.
{

Dim strFiter as String  ="Table2.id='" + table1.id +"'"
Dim dRows() as DataRow=ds.Tables(table2).Select(strFilter)
dim strBirthday as String=dRows(0)("Birthdate")

' Now you get strBirthDay make a query like

Dim strSQL as String ="UPDATE Table1 Set birthdate ='" + strBirthDay + "'"

' and using this strSQL you can update the Table2
}
0
 
omagarcAuthor Commented:
Wasn't exactly what I was looking for but put me on a path. Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now