Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

New to MSSQL - need help with a query to remove spaces within a field

$
0
0

After data conversion the leading and trailing spaces were removed from the data in the "tag" column.  However spaces in the middle of the column were not removed.  Tag data must be unique.  When I run an update script I get the message that "Cannot insert duplicate key in object 'mytablename'.   This tells me that my data looks like this:

AAAAA[space][space]BBBBB --unique tag

AAAAA[space]BBBBB -- unique tag

If I remove the spaces from each I will have duplicates.  Therefore I'd like to update the records as follows:

AAAAABBBBB --unique tag

DUP-AAAAABBBBB -- unique tag

How can I write a script that not only removes the spaces but also identifies the duplicate record?


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>