hi all,
I have a scenario where in i need to replace repeating blanks with a single blank of a column in the database.
ex: ASD KL OP ---> ASD KL OP
any suggestions??
Regards,
Leela
9 1559
hi all,
I have a scenario where in i need to replace repeating blanks with a single blank of a column in the database.
ex: ASD KL OP ---> ASD KL OP
any suggestions??
Regards,
Leela
the challenge: you don't know at any point in time how many spaces are there in between. this is string cleaning (like address), you might want to create a function that parse the string and remove repeating blanks. consideration: not because you can not see does not mean it's blank. there are "unprintable" characters.
-- CK
the challenge: you don't know at any point in time how many spaces are there in between. this is string cleaning (like address), you might want to create a function that parse the string and remove repeating blanks. consideration: not because you can not see does not mean it's blank. there are "unprintable" characters.
-- CK
but in my case i am sure that its a space but is there any one liner function which can do this trick?????
but in my case i am sure that its a space but is there any one liner function which can do this trick?????
is this a one time project? how many fields are you trying to clean up?
-- CK
is this a one time project? how many fields are you trying to clean up?
-- CK
its not a project or something, there is one column in the database which has spaces in between and needs to be removed.
its not a project or something, there is one column in the database which has spaces in between and needs to be removed.
if it's a one-time, manual kind of task try: -
update yourtable
-
set yourfield = replace(replace(replace(yourfield,' ',' '),' ',' '),' ',' ')
-
where patindex('% %',yourfield) > 0
-
you're going to have to run this a number of times, until it no longer returns any resultset. it will just replace any 2 consecutive space with 1 space. so, if there are 3 spaces in between string, it will be reduced to 2, but the second replace will reduce it further to 1. if there are 4 it will reduce to 2, and so on...
you can try this first: -
select yourfield, replace(replace(replace(yourfield,' ',' '),' ',' '),' ',' ')
-
from yourtable
-
where patindex('% %',yourfield) > 0
-
this will give you an idea if you're in the right direction
-- CK
thanks for ur info... :)
this i have tried i wanted some other better approach than this if any........
create a string parser function...
-- CK
Create FUNCTION [dbo].[replace_blank]
( @input nvarchar(max))
RETURNS nvarchar(4000) As
Begin
Declare @output nvarchar(4000)
SET @input = ltrim(rtrim(@input))
SET @output = ''
While 1=1
Begin
IF PATINDEX('% %',@input) = 0 BREAK
SET @output = ltrim(rtrim(@output))+' '+ltrim(rtrim(SubString(@input,1,CharIndex(' ',@input))))
SET @input = SubString(@input,CharIndex(' ',@input)+1,Len(@input))
End
SET @output = Left(@output,Len(@output))+' '+@input
Return @output
End
-- select dbo.replace_blank('hello: is this the one you looking at?. ')
Or you can use
-----------------------------
Create FUNCTION [dbo].[replace_blank]
( @input nvarchar(4000))
RETURNS nvarchar(4000) As
Begin
While 1=1
Begin
IF PATINDEX('% %',@input) = 0 BREAK
SET @input = replace(@input,' ',' ')
End
SET @input = ltrim(rtrim(@input))
Return @input
End
-------------------------------
-- select dbo.replace_blank('hello is this the one you looking at. ')
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Moon |
last post by:
Seems I still haven't got the hang of all those window generating code
in Javascript. I've got a page with about 15 photo thumbnails. When you
click on a thumbnail a new window pops up which shows...
|
by: William Kossack |
last post by:
I have an Access table with one primary key and am attempting to update
a non-key field, using
UPDATE tblMethtest SET fev1timemeth = '' WHERE SID = '0041R';
When I do this, the field...
|
by: Christoph Boget |
last post by:
When building a form using Infopath, you can define a repeating
section and stick form fields in that section. I'm curious if ASP.NET
has a similar control to make it easy to design something...
|
by: Registered User |
last post by:
Hi experts,
I'm trying to write a program that replaces two or more consecutive
blanks in a string by a single blank.
Here's what I did:
#include <stdio.h>
#include <string.h>
#define MAX 80
|
by: wyo |
last post by:
I'd like to display folder names without line breaks so I tried the
following replace
folders = f.replace(/ /g, ' ');
but the script stop without an error. Any idea? Is there a better...
|
by: Diego F. |
last post by:
Hi all.
I have an application that receives a message from a socket in an array from
a certain size. As the array size may be longer that the message received,
the end of the array has blank...
|
by: Ronald S. Cook |
last post by:
I have a DataTable with column "Sequence". Values are like:
Sequence
--------
5
1
3
(blank/null)
7
6
|
by: dhascuba |
last post by:
The @name field can contain a single quote in it such as: Mike O'Grady.
Since this is creating and SQL statement on the server side, it will not process the name if it has a single quote in it. Id'...
|
by: eBob.com |
last post by:
I have a RichTextBox in which I'd like blanks to appear different from
nothing. Imagine a file which does not fill up the RTB. You can't tell how
many, if any, blanks might follow the last...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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,...
| |