Question

If SQL Query - Excel as Database

  • 19 April 2023
  • 4 replies
  • 363 views

Badge +1

 

if ((select count[Colname] from [Tablename$$] where [Clasificacion] = 'A') > 1)

begin

Update [Tablename$$] Set [Status] = 'Test' where [Colname] IN ('X','Y') and [Clasificacion] ='A'

end

 

Can we use If and update together in AA360?

I want to identify if a set of values exists or not in excel table and then need to update status.

I have tried using the above code but it is throwing SQL syntax error.

How to achieve this or Is there any other approach ?


4 replies

Badge +2

There is no apparent syntax error in this code. However, the expression count[Colname] should have parentheses around the count function, so the square brackets should be removed. The correct code should be:

if ((select count(Colname) from [Tablename$$] where [Clasificacion] = 'A') > 1)
begin
  Update [Tablename$$] Set [Status] = 'Test' where [Colname] IN ('X','Y') and [Clasificacion] ='A'
end
 

Badge +1

It is still throwing syntax error

Badge +2

if ((select count([Colname]) from [Tablename$$] where [Clasificacion] = 'A') > 1)
begin
    Update [Tablename$$] Set [Status] = 'Test' where [Colname] IN ('X','Y') and [Clasificacion] ='A'
end

Try this  -> count([Colname])

Userlevel 1
Badge +4

Have you considered using the IF logic in AA surrounds by 2 DB calls -

the 1st DB query would return the count of records found 

use AA  IF logic to test the result to be > 0

the 2nd DB statement would be the update.

 

Reply