Interview Question in Data Transformation Services (DTS)


 

Interview Question :: I need to create a SQL Server Function to strip unwanted characters from a table


I am exporting data from a table to import into a nother database (MapQuest) In my database I have characters such as ' example Jim's Store the single quote in Jim's (') is causing the import to fail. Just like Unit "C" in the address field, the double quote causes it to fail.

I am exporting the data through a DTS package, the first step is to fire a stored procedure to grab the data and what I want to do is call a user defined function that will strip the data of any unwanted characters that I specify in the function when it grabs the data.
Answers to "I need to create a SQL Server Function to strip unwanted characters from a table"
RE: I need to create a SQL Server Function to strip unwanted characters from a table?

There's a T-SQL function in sql server that replaces characters.



You can try the REPLACE T-SQL function



REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )



Arguments

'string_expression1'



Is the string expression to be searched. string_expression1 can be of character or binary data.



'string_expression2'



Is the string expression to try to find. string_expression2 can be of character or binary data.



'string_expression3'



Is the replacement string expression string_expression3 can be of character or binary data.
 
Vote for this answer ::  
RE: I need to create a SQL Server Function to strip unwanted characters from a table?

Yea I ran into this one a few years ago its a doozy but I was able to get it fixed.



On that column that you have the apostrophe you need to use the REPLACE function on it



like - REPLACE(<Column Name> , '', '''') - That will fix your problem with the apostrophe.



REPLACE(<Column Name>, '''', '"') - This will fix your problem with the double quotes. What essentially your doing is replacing the existing quotes which are viewed as single quotes to double quotes
 
Vote for this answer ::  
Update Alert Setting