Oh, so what, in the spreadsheet tells you what row in the table the new email address belongs to?
No it wont tell me what row. What the spreadsheet will have is the username and the new email address....
So it would be like this
username email address
In the table where I need to update the email address column there is also a username column..
According to your original post, you already have the data in the table, so we don't actually need to worry about the spreadsheet. Just what's in the table.
I don't know what your table name is or the datatypes but, if all you want to do is change every occurrence of "@Hotmail.com" to "@GMail.com", the substitute the correct schema name and table name into the following code and it should do fine. You included a space in the "email address" column, which is why it's included in brackets. You may have to change that as well.
Once you made the necessary changes to the following code, run it.
SET = REPLACE(,'@Hotmail.com','@GMail.com')
WHERE LIKE '%@Hotmail.com%'
-- ROLLBACK -- COMMIT
IF the returned rowcount is what you expected, then double-click on COMMIT to select it and run just the COMMIT code to make it permanent.
If the returned rowcount is NOT what you expected, then double-click on ROLLBACK to select it and run just the ROLLBACK code to undo the update and then figure out what went wrong.
As a bit of a sidebar, some people like to run their UPDATE code as a SELECT first as a bit of a test. I usually do the same but, either way, I always use the BEGIN TRANSACTION and the commented out ROLLBACK and COMMIT to help keep accidents from happening. Never walk away from an active transaction because you could end up blocking the database up pretty good.
My next suggestion, since you're a newbie, would be to spend some time studying SQL Server and T-SQL (the language).
is pronounced "ree-bar
" and is a "Modenism
" for R
First step towards the paradigm shift of writing Set Based code:
________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
"If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
"Change is inevitable... change for the better is not."
When you put the right degree of spin on it, the number 3|8
is also a glyph that describes the nature of a DBAs job. 😉
How to post code problems