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!

Selecting from one field then updating into another

Status
Not open for further replies.

Talnaus

Programmer
Mar 24, 2005
3
US
I am trying to select data from one field and updating it into a different field thats in the same row. But i dont really know where to begin since im new to SQL, i know i got to start with a select but how to i then use that to update into the other field ?
 
OK i got it to update one row at a time like

update tblFPPets
set AcctNum = LicenseNum, LicenseNum = null
where DateLicenseExpires < getdate() and OwnerID_FK = 8

but when i try to do it on the entire database like

update tblFPPets
set AcctNum = LicenseNum, LicenseNum = null
where DateLicenseExpires < getdate()

i get this error

Server: Msg 2627, Level 14, State 2, Line 1
Violation of UNIQUE KEY constraint 'UQ__tblFPPets__0880433F'. Cannot insert duplicate key in object 'tblFPPets'.
The statement has been terminated.
 
Ah, thanks, didnt realize that till you mentioned it i removed the unique constraint and it worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top