We help IT Professionals succeed at work.

Different String delimitator in a TSQL sentence

250 Views
Last Modified: 2012-05-08
Consider the following situation:

1- An application reading a text file.
2- Maybe some of the records contain Single or Double quotes
3- The application must build a TSQL sentence to insert the data into the database
4- The data quotes could be at the beginning and/or the end of a field or perhaps in the middle.
5- How many adjacent quotes is not known

The problem:

When enveloping the data field into single or double quotes and running it against SQL Server 2005 it raises an exception when there are quotes already into it.

Example:

Data:  The Vendor's device is blue
SQL:  INSERT INTO dbo.MyTable SELECT 'The Vendor's device is blue'  -- This raises an error

Is there a way to change the strings delimitator to use for example pipes instead of quotes?

SQL:  INSERT INTO dbo.MyTable SELECT |The Vendor's device is blue|
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Yes I worked for me.

The application was a sort of a custom DTS except that files reside in User's computer. There is some pre-processing involved according with dynamic parameters. That's why quotes processing was mandatory.

Thank You.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.