Skip to main content

Hello All,

I’m using excel as DB to query . I have established the connection and able to select the sheet using read activity. problem is with update as there is no unique column data to WHERE clause in updating , how to deal with this scenario in AA?

Hi ​@Adarsh Nambiar,

If you are having excel with No Column header, then used below connection string to connect excel as Database.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source='<Excel_Path>';Extended Properties="Excel 12.0 Xml;HDR=NO";

 

Example:

If you use the select * query without WHERE clause, it shows like this:

F1 F2 F3
Nithish 9988564159 Male
Ganesh 9854237856 Male
Mahesh 9585453585 Male
Pranesh 9185453518 Male
Saanvi 8756128546 Female
Rajani 9185453583 Female

 

Then if you want to Update Nithish’s Phone number(F2) to “9999999999” 

Update oSheet1$$] Set F2="9999999999" Where F1="Nithish"

or want to Update Rajani (f1) Name as “RAJANI MR”

Update >Sheet1$$] Set F1="RAJANI MR" Where F1="Rajani"

Select F1, F2 from eSheet1$$]

F1 F2
Nithish 9999999999
Ganesh 9854237856
Mahesh 9585453585
Pranesh 9185453518
Saanvi 8756128546
RAJANI MR 9185453583

 

This tells, how to update excel using SQL in AA  for non header records.

 

If this also not solving the problem, then please revert here with screenshot or data of excel template and what action you need to perform.

Thanks!

 

 


I’m going to start off with my short message that Excel is not a database. (Okay, I’m done.)

That being said, your question is more of a SQL question than an AA question: How can you update a row (record) of data with no unique key.

Let’s say we have this sample data:

First Name Years of Service Received Award
Aaron 7 No
Janet 12 No
Charles 3 No

We can easily query this and get all the people who have worked for the company for more than 5 years like this:

select “first name”, “years of service”, “received award” from employees where “years of service” > 5;

I can use a similar where clause to update the table after presenting people with the awards for having more than 5 years of service like this:

update employees set “received award” = ‘Yes’ where “years of service” > 5;

This updates the table for Aaron and Janet to be Yes in the Received Award column.

If you have some sample data that you would like reviewed, let me know.


Hi ​@Adarsh Nambiar ,

 

If no single column is unique, why don't we use a combination of values across multiple columns serve as a unique identifier?

You can create a logical WHERE clause using multiple columns like:
WHERE Col1 = 'X' AND Col2 = 'Y' AND Col3 = 'Z'

 

 


@Padmakumar Yes. Having multiple logical operators within a WHERE is completely okay. You can also use parenthesis to force certain operators to execute before others, similarly to how parenthesis works in math.


@Adarsh Nambiar if any of these suggestions helped, feel free to mark one as best answer!


Reply