views:

88

answers:

4

Hello ! I have two columns with two values.. I want to append some text to the left of all the cells of Column A and concatenate to the right of all the cells of Column B.

Basically I'm trying to avoid having to type in a whole bunch of sql updates. so for example if i have an excel with

ID Employee Name
135 Rasputin
76 Bush

I want to generate something like this

UPDATE EMPLOYEES SET ID = '135', WHERE employee_name= 'RASPUTIN'
UPDATE EMPLOYEES SET ID = '76', WHERE employee_name= 'BUSH'

So perhaps a solution of appending text to the cells and then merging the rows?

I prefer a built in function as I'm not familiar with VBA thanks!

PS crossposted on superuser but no response yet.

A: 

There is a CONCATENATE function in Excel.... I've used this function many times to generate SQL queries based on Excel spreadsheet data

This code works provided your Id column is A and your name is in B


=CONCATENATE("UPDATE EMPLOYEES SET ID = '",A1,"', WHERE employee_name= '",B1,"'")
Anthony Shaw
however, your SQL syntax may be incorrectUPDATE EMPLOYEES SET ID = '135' WHERE employee_name= 'RASPUTIN'UPDATE EMPLOYEES SET ID = '76' WHERE employee_name= 'BUSH'(without the commas, however I've never tried with, so maybe that would work too)
Anthony Shaw
A: 

If I understand correctly:

="UPDATE EMPLOYEES SET ID = '" & A2 & "', WHERE employee_name = '" & B2 & "'"

should be what you want (assuming the id is in column A and the name in column B).

mavnn
+1  A: 

Can't you create a formula in column C1 which says something like:

="UPDATE EMPLOYEES SET ID ='" & A1 & "', WHERE employee_name = '" & B1 & "'"

And then copy that formula down. You should then be able to cut and paste that into your SQL query application.

wocko
A: 

Answered correctly in superuser http://superuser.com/questions/55262/append-a-text-string-to-the-left-of-all-the-cells-of-a-column-in-excel-2002

Thanks for the answers! This did the trick:

="UPDATE EMPLOYEES SET ID = '" & A1 & "' WHERE EMPLOYEE = '" & B1 & "'"

Ayrad