473,625 Members | 3,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing white spaces in a varchar column

Rad
I have a table . It has a nullable column called AccountNumber, which
is of varchar type. The AccountNumber is alpha-numeric. I want to take
data from this table and process it for my application. Before doing
that I would like to filter out duplicate AccountNumbers. I get most of
the duplicates filtered out by using this query:

select * from customers
where AccountNumber NOT IN (select AccountNumber from customers where
AccountNumber <> '' group by AccountNumber having count(AccountNu mber)
1)


But there are few duplicate entries where the actual AccountNumber is
same, but there is a trailing space in first one, and hence this
duplicate records are not getting filtered out. e.g
"abc123<whi te-space>" and "abc123" are considered two different entries
by above query.

I ran a query like :

update customers set AccountNumber = LTRIM(RTRIM(Acc ountNumber)

But even after this query, the trailing space remains, and I am not
able to filter out those entries.

Am I missing anything here? Can somebody help me in making sure I
filter out all duplicate entries ?

Thanks,
Rad

Sep 15 '05 #1
3 17938
Stu
Are you sure it's a whitespace? It might be a line break. To verify,
you might try something like:

SELECT AccountNumber
FROM customers
WHERE AccountNumber LIKE '%" + CHAR(10)
OR AccountNumber LIKE '%' + CHAR(13)

Oh, and always be cautious about running an UPDATE statement with no
WHERE clause.

HTH,
Stu

Sep 15 '05 #2
Rad
Thanks Stu, you made my day. :)

It was a line break after a white space. I was concentrating only on
the white space and did not notice the line break. So in my first
statement, I first use this query:

UPDATE customers
SET AccountNumber = substring(Accou ntNumber, 1, PATINDEX('CHAR( 13)',
AccountNumber))
WHERE AccountNumber like '%' + CHAR(13)

and it worked!

Thanks again!

Regards,
Rad

Stu wrote:
Are you sure it's a whitespace? It might be a line break. To verify,
you might try something like:

SELECT AccountNumber
FROM customers
WHERE AccountNumber LIKE '%" + CHAR(10)
OR AccountNumber LIKE '%' + CHAR(13)

Oh, and always be cautious about running an UPDATE statement with no
WHERE clause.

HTH,
Stu


Sep 15 '05 #3
>> table . It has a nullable column called AccountNumber, which is of VARCHAR(n) type. <<

That is a very bad code design because it prevents check digits and
makes validation rules more complex. If you had validation rules in the
DDL, you would not have this problem. First mop the floor, then fix
the leak.

Sep 17 '05 #4

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

Similar topics

5
3305
by: qwweeeit | last post by:
Hi all, I need to limit as much as possible the lenght of a source line, stripping white spaces (except indentation). For example: .. . max_move and AC_RowStack.acceptsCards ( self, from_stack, cards ) must be reduced to: .. . max_move and AC_RowStack.acceptsCards(self,from_stack,cards) My solution has been (wrogly): ''.join(source_line.split())
4
3209
by: ucfcpegirl06 | last post by:
Hi, I need help getting rid of trailing white spaces. I am searching a file for various data (not important) and retrieving it. I output the data if found to a file. An example would be: HD='Three blind mice ' My output would consist of: Three Blind Mice (w/ all the white space behind being printed until the quote mark is reached) I don't the white space after the text to be printed.
11
15000
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white spaces(if it more than once between two words). Is there any function we have in C which will find out the tabs and white spaces and returns the text in the follwong way -
3
3361
by: Prince | last post by:
I have some <RequiredFieldValidator> on my page and everything works fine except that there are lots of white spaces between the web server controls that are being validated. I've set the Display properties for all the controls to "Dynamic" and still I can't get rid of the white spaces between controls. It's as if there are bunch of <br> tags separating the controls. For example,the "HTML" look similar to this.
1
1945
by: Brian Mitchell | last post by:
I'm sorry if this is the wrong group but I couldn't find one relating to cryptography. I have a byte array that I am encrypting using the System.Cryptography classes and it encrypts just fine. However when I decrypt the array the decryptor removes all the white spaces from the array (byte values of 255). I've tried setting the padding to none but it doesn't work. As long as the array doesn't have any white spaces in there it encrypts...
3
1912
by: ayan4u | last post by:
well i need to deal with white spaces in charecter arrays... with static arrays its fine.. char ss; cin.getline(ss, sizeof ss); .... //deals with white spaces
1
3753
by: RGow | last post by:
Hi, I'd like to know whether there is a way to alter the data type of a VARCHAR FOR BIT DATA column to be simply a VARCHAR column? I executed an ALTER TABLE statement, similar to, ALTER TABLE tab_name ALTER COLUMN col_name SET DATA TYPE VARCHAR(100) without any problems. However, a simple Java application reports via JDBC that the column type is still VARCHAR FOR BIT DATA.
0
1730
Krishna Ladwa
by: Krishna Ladwa | last post by:
In Sql Server 2000 Version, I found that no Notification message box appears when converting text column to varchar but the data gets truncated to the given size for the varchar. Whereas it appears when you convert the varchar column to text column. Do this through Enterprise Manager Console Create a New table with a column as varchar datatype from Enterprise Manager  table created  Open the table and add one row  Successfully added the...
2
29342
by: KSG01 | last post by:
Source Public Function NoWhiteSpace(ByVal strText As String) As String Return System.Text.RegularExpressions.Regex.Replace(strText, " ", _ String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase) End Function Demo Dim Test As String = " This is a simple test for No white spaces function "
0
8256
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6118
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2621
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
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.