473,587 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need your help to remove spaces in the column entries using SQL

Hi all,

I am new to these so plz never mind if this is funny.

here is my problem :

Table : moody

Column : Title

New column : Nospace

I have data in "Title" column of many rows which are normal sentence.

My requirment is to remove the "white space", +, | , ., / , ! @, $, %
etc special characters and fill it by ( hyphen) and put it in new
"Nospace" Column

Example :

I have : Hurray ! I won the Game

Needed : Hurray-I-won-the-Game

Can any body helpme in getting an SQL Query for this if possible

Thanks in Advance

Oct 21 '06 #1
4 23796
Make a list of all the "white space" characters.

Use REPLACE to change each of them to the dash character. You could
nest them, but it might be simpler to loop through them, changing one
white space character in each UPDATE.

Then reduce multiple dashes to one by using REPLACE(whateve r, '--',
'-') until no more rows are updated.

Roy

On 21 Oct 2006 09:05:10 -0700, fe****@gmail.co m wrote:
>Hi all,

I am new to these so plz never mind if this is funny.

here is my problem :

Table : moody

Column : Title

New column : Nospace

I have data in "Title" column of many rows which are normal sentence.

My requirment is to remove the "white space", +, | , ., / , ! @, $, %
etc special characters and fill it by ( hyphen) and put it in new
"Nospace" Column

Example :

I have : Hurray ! I won the Game

Needed : Hurray-I-won-the-Game

Can any body helpme in getting an SQL Query for this if possible

Thanks in Advance
Oct 21 '06 #2
Nesting the function calls is better because it gets done with ONE
update statement instead several.

Oct 22 '06 #3
On 22 Oct 2006 05:12:00 -0700, "--CELKO--" <jc*******@eart hlink.net>
wrote:
>Nesting the function calls is better because it gets done with ONE
update statement instead several.
That may very well prove to be an important advantage.

On the other hand, if you accept replacing them one at a time you
could put the characters to be replaced in a table. An advantage to
that would be that adding or subtracting from the set of characters
would be a simple INSERT or DELETE transaction. When nesting changes
to the list requires coding changes.

So, as so often is the case, It Depends.

Roy Harvey
Beacon Falls, CT
Oct 22 '06 #4
On 21 Oct 2006 09:05:10 -0700, fe****@gmail.co m wrote:

(snip)
>My requirment is to remove the "white space", +, | , ., / , ! @, $, %
etc special characters and fill it by ( hyphen) and put it in new
"Nospace" Column

Example :

I have : Hurray ! I won the Game

Needed : Hurray-I-won-the-Game

Can any body helpme in getting an SQL Query for this if possible
Hi feucos,

This is actually quite hard to achieve in straight SQL. Replacing the
various special characters with hyphens is easy, using a nested REPLACE
function - but that would leave you with 'Hurray---I-won-the-Game'.
Removing double hyphens is a lot harder, since there is no maximum
number of hyphens.

If you're on SQL Server 2005, I'd use a CLR user-defined function. Using
CLR means that yoou can use the power of regular expressions to do the
search and replace as quickly as possible.

For SQL Server 2000, you'll either have to use a T-SQL user-defined
function to loop over the characters in the string (but that will be
very slow), or use an awfully ugly but probably lots faster nested
REPLACE function like this:

REPLACE(REPLACE (REPLACE(....RE PLACE(Title, ' ', '-'), '+', '-'), '|',
'-'), ......, '%', '-'), '---------', '-'), '-----', '-'), '---', '-'),
'--', '-')

This will handle series of up to 16 whitespace/special characters. Fill
in the appropriate amount of "REPLACE(" on the first series of dots, and
add "'#', '-')" for each special character to be replaced on the second
series of dots.

--
Hugo Kornelis, SQL Server MVP
Oct 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6604
by: Dariusz | last post by:
I have PHP code (below) which reads data from a MySQL format database. The problem I am having is trying to find out when the last ID entry was made. When the script is executed, the $gbID is supposed to be read and display the last entered ID number ($How_many_entries) - the ID number is entered / updated automatically in another PHP script...
20
1678
by: Joey Martin | last post by:
I am scanning an HTML file. I need to gather certain data from areas that start with <SMALL> text. Let me show the code, then explain more. ---- Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFile(TheFilePath) Set ts = f.OpenAsTextStream(1,-2)
8
6274
by: carmoda | last post by:
this is a question for someone smarter than me: how would i go about removing just the first character in a column? i.e: if i wanted to remove the 'A' in the ItemSKU column ItemID ItemSKU ItemName 1 A09807969 Red T-Shirt 2 A09807970 Green T-Shirt 3 A09807975 Blue Skirt
28
3284
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical make-believe challenge in order to avoid confusing the issue further. Suppose I was hosting a dinner and I wanted to invite exactly 12 guests from my...
2
1715
by: Sebastian | last post by:
The following query needs about 2 minutes to complete (finding dupes) on a table of about 10000 addresses. Does anyone have an idea on how to speed this up ? Thanks in advance !!! Sebastian
21
3340
by: Thelma Lubkin | last post by:
I would like my DLookup criteria to say this: Trim(fieldX) = strVar: myVar = _ DLookup("someField", "someTable", "Trim(fieldX) = '" & strVar & '") I don't believe that this will work, and I won't be at a machine with access to Access for a while, so can someone please tell me how to write this? thanks, --thelma
4
2451
by: rdemyan via AccessMonster.com | last post by:
I have the following SQL statement in code that is set to the RowSource of a combobox. The combobox has two columns. SELECT '(ALL)' As Site, '' As , 0 As SortFirst FROM GROUP BY SITE_COMPLEX UNION SELECT SITE_COMPLEX As Site, Count(BLDG_ID) As , 1 As SortFirst FROM
1
9873
by: feucos | last post by:
Hi all, I am new to these so plz never mind if this is funny. here is my problem : Table : moody Column : Title
3
1670
by: Dorish3 | last post by:
Hello, I am a novice with MS Access so I want to apologize ahead of time with the fact that I know very little about Access. I have an Access database that keeps track of volunteers and assigns them out to specific events(this is a high end entertainment center). They of course have volunteers that come in for specific events who donate...
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.