Select to view content in your preferred language

SQL Executor syntax for update statement using @Value for a string

308
5
Jump to solution
06-03-2024 01:58 PM
MichaelKohler
Occasional Contributor III

We have a FME workspace where I need to update rows in the table that meet a where condition. The condition is a string value. When I set up the sql statement it is like this.

UPDATE ADDRESSES.dbo.ADDRESSES_TEST set internalonly = 1 where 'PARCELID' = @Value(PARCEL_NUMBER)

and when the executor is run, the below error is returned for each feature.

Query failed, possibly due to a malformed statement. Query Text   UPDATE ADDRESSES.dbo.ADDRESSES_TEST set internalonly = 1 where 'PARCELID' = 342073103690008  Provider error `(-2147217913) Error converting data type varchar to numeric.'

The PARCEL_NUMBER and the PARCELID fields are TEXT in both instances. This is what was used in python.

UPDATE ADDRESSES_TEST SET internalonly = 1 WHERE PARCELID = '{}'

 where the PARCEL_NUMBER is quoted. Also, internalonly is a smallint in both databases

Any leads would be greatly appreciated.

0 Kudos
1 Solution

Accepted Solutions
MarceloMarques
Esri Regular Contributor

use SQL Server function CAST or CONVERT 
https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-...

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov

View solution in original post

5 Replies
BruceHarold
Esri Regular Contributor

Michael the single quotes around PARCELID make it a literal and not an identifier.  Just remove them.

0 Kudos
MichaelKohler
Occasional Contributor III

Thanks for the quick reply.

Both statements with, and without the single quote return the same error.

 

UPDATE ADDRESSES.dbo.ADDRESSES_TEST set internalonly = 1 where 'PARCELID' = @Value(PARCEL_NUMBER)

Microsoft SQL Server Non-Spatial Reader: Query failed, possibly due to a malformed statement. Query Text `UPDATE ADDRESSES.dbo.ADDRESSES_TEST set internalonly = 1 where 'PARCELID' = 340750300650005'. Provider error `(-2147217913) Error converting data type varchar to numeric.'

and

UPDATE ADDRESSES.dbo.ADDRESSES_TEST set internalonly = 1 where PARCELID = @Value(PARCEL_NUMBER)

Microsoft SQL Server Non-Spatial Reader: Query failed, possibly due to a malformed statement. Query Text `UPDATE ADDRESSES.dbo.ADDRESSES_TEST set internalonly = 1 where PARCELID = 342073108650005'. Provider error `(-2147217913) Error converting data type nvarchar to numeric.'

 

The parcel number is a text string and should have quotes. This works with python and in SQL.

update ADDRESSES_TEST set internalonly = 1 where PARCELID = '342073103690008'

 

if i take the quotes away from the PARCELID and run in SQL, the same conversion error is given

Error converting data type nvarchar to numeric.

 

Very much appreciate your help.

 

 

0 Kudos
MarceloMarques
Esri Regular Contributor

use SQL Server function CAST or CONVERT 
https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-...

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov
MichaelKohler
Occasional Contributor III

Thank you. That did the trick

UPDATE ADDRESSES.dbo.ADDRESSES_TEST set internalonly = 1 where PARCELID = CAST(@Value(PARCEL_NUMBER) As nvarchar)

MarceloMarques
Esri Regular Contributor

Glad to help.

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov
0 Kudos