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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems writing Update statement

Status
Not open for further replies.

Bigced21

Programmer
Feb 5, 2003
76
US
I'm having a problem writing the code for this.
what I'm trying to do is update the tbl Blr_temp_contact by setting the Ref_ID equal to the Blr_temp_contact.id where the first bus_name is listed. Import_ID is equal to the ID in the tbl Blr_import. Let me give you an example of what I want the data to look like. Pay attention to the Ref_ID of what I want it to do.

For Ex. Ref_id - 4, 2

id import_id ref_id Bus_name
-----------------------------------------------
1 32151 1 KENTON CO FISCAL COURT KY
2 32152 2 COMMONWEALTH OF KY
3 32153 3 BENHAM SCHOOL HOUSE
4 32154 4 LAUREL HEIGHTS HOME
5 32155 4 LAUREL HEIGHTS HOME
6 32158 2 COMMONWEALTH OF KY
7 32159 7 THE SALVATION ARMY
8 32160 8 MASONIC HOME OF KY

This is what I have so far:
Update Blr_temp_contact
set Ref_ID = ID
where Import_ID IN
(Select id
from Blr_import
where owner_name = Blr_temp_contact.bus_name
)
Am I even close to the data I'm trying to view?

 
You have two tables here - probably need to give some info on the second one but from the description I'm not sure why it is needed.

Your query will not affect the table as it is updating ID to itself.

Update Blr_temp_contact
set Ref_ID = (Select min(t2.id)
from Blr_temp_contact t2
where t2.bus_name = Blr_temp_contact.bus_name
)


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top