2

In SQL Server, I have this query

SELECT DISTINCT  City FROM 
Person.Address

But this gives me two cities which has name like Ville De'anjou (i.e. ')

you can try the same by this

SELECT DISTINCT  City FROM 
Person.Address
WHERE City like '%''%'

Now, I am creating a SSIS package which is creating folder for each city. But the package fails at these two cities and throw this error

[ADO NET Source [1]] Error: An error occurred executing the provided SQL command: "SELECT AddressID, AddressLine1,PostalCode, City
 FROM Person.Address WITH(NOLOCK)
 WHERE City = 'Ville De'anjou'". Incorrect syntax near 'anjou'.
Unclosed quotation mark after the character string ' SET FMTONLY OFF;'.

It fails because this isn't a correct query.

I have tried with this but no luck, instead it removed those two cities from the list

SELECT DISTINCT CITY FROM Person.Address
WHERE City like REPLACE(City,'''', '''''')

How can I rectify this error?

1

1 Answer 1

3

How about:

SELECT DISTINCT REPLACE(City,'''', '''''') FROM Person.Address
WHERE City like '%''%'
Sign up to request clarification or add additional context in comments.

1 Comment

that works when I hard coded the city name. but i want that to be replaced at the time of select only. I.e. SELECT DISTINCT City FROM Person.Address

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.