in Education by
I have a table where I have a ColumnA which has data with white spaces and special characters. I want to generate ColumnB with the data from ColumnA with the removal of white spaces and special characters. For example, ColumnA has values like: N/A @email Hot-topic #sql#% White paper. I want a new column with values: NA email HotTopic sql Whitepaper I tried below SQL in SSMS, but it is not working completely. Could someone help me out? SELECT code, REPLACE(REPLACE(code, TRIM(TRANSLATE(code,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',' ')) ,'') ,' ','') FROM SAMP It is not working for the record with value: #sql#% JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Added as a wiki answer in order to retain the comment made by @lptr. Query by @lptr explanation mine (@DaleK). Your attempt was close, but only worked for single characters... the one that failed was because you had multiple characters that needed replacing and once you remove the white space they are all next to each other and don't match the original string anymore. This answer cleverly replaces all the letter characters with a "*" using translate as step 1, then using translate again on the original column value, replaces all the non-letter characters with a "*" as step 2, then finally replaces all "*" characters with an empty string. Note also the use of replication to avoid typing the same character in multiple times. create table samp(code varchar(50)); insert into samp(code) values ('N/A'), ('@email'), ('Hot-topic'), ('#sql#%'), ('White paper. '); select s.code, n.nonletters, l.letters from samp as s cross apply (values(translate(s.code, 'abcdefghijklmnopqrstuvwxyz', replicate('*', 26)))) as n (nonletters) cross apply (values(replace(translate(s.code, n.nonletters, replicate('*', len(n.nonletters+'.')-1)), '*', ''))) as l (letters);

Related questions

0 votes
    I've been following this video( to install bWAPP on Parrot ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I would like to ask for performance of SQL. This is my query: Select A.code ,A.name ,(Select B. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 00: ... How can I get that? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into ... Peter, Paul, Mary? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    In SQL Server, it's possible to insert into a table using a SELECT statement: INSERT INTO Table (col1, col2, ... .id = other_table.id Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    What is the difference between the EXISTS and IN clause in SQL? When should we use EXISTS, and when should we use IN? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    What is the difference between the EXISTS and IN clause in SQL? When should we use EXISTS, and when should we use IN? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    i want to delete the wullfi row by match the authid i must also say the aid is change so cant ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm using the Microsoft Access to do the SQL and is there any way for me to set the criteria for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    What's the best way to store a linked list in a MySQL database so that inserts are simple (i.e. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    What's the best way to store a linked list in a MySQL database so that inserts are simple (i.e. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    What's the best way to store a linked list in a MySQL database so that inserts are simple (i.e. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    What's the best way to store a linked list in a MySQL database so that inserts are simple (i.e. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    What's the best way to store a linked list in a MySQL database so that inserts are simple (i.e. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    What's the best way to store a linked list in a MySQL database so that inserts are simple (i.e. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
...