July 9, 2008 at 3:44 am
Hi,
How to handle white space in sql 2005. Is there any specific collation setting available for handling white space
Regards,
S.Balavenkatesh
July 9, 2008 at 6:20 am
You have to be more specific. White space is a generic term that includes spaces, carriage returns, line feeds, NULL, etc. In many cases, you need to retain these characters, in some cases you want to remove them. You have data types that force you to have it (CHAR()) and some that do not (VARCHAR()).
Do you have a specific place you need to remove some of these characters?
July 9, 2008 at 6:41 am
We need to store Whitespace in Primary Key as in oracle . For Eg "Word" and "Word " should be stored in the primary key column without any problem.
Also I need to have "Axa" and "AxA" treated as two separate objects
Hope this clarify you.
How to solve this issues.
Regards,
S.Balavenkatesh
July 9, 2008 at 6:41 am
Also I need to have "Axa" and "AxA" treated as two separate rows in the primary key
July 9, 2008 at 6:49 am
Not that I would advocate what you are doing - looks like a real nightmare to me, but you just need to use a case-sensitive collation for the column. Look them up in bools online.
July 9, 2008 at 7:01 am
Hi
Now i use SQL_Latin1_General_CP1_CI_AS collation settings.
It works for white space before the values. (Eg.' Bala')
It shows error on when i insert like this ('Bala ')
The name column is the primary key when i insert the following values ('Bala'), ('BalA') it shows primary key violation error.
Is there any specific setting used to solve this issues.
Regards,
S.Balavenktesh
July 9, 2008 at 7:09 am
The "CI" indicates case-insensitive. "A" and "a" are the same. If you want the same collation but case-sensitive, it is: SQL_Latin1_General_Cp1_CS_AS
I suggest you look carefully at the collation options and make sure you understand the implications of their use.
July 9, 2008 at 7:15 am
Hi,
Thanks for your help. It works for ('Bala','BalA')
But it is failed on tailing white space on the values ('Bala ')
Regards,
S.balavenkatesh
July 9, 2008 at 7:23 am
In saying that it fails for "Bala " are you saying that you want that recognized as a seperate item?
July 9, 2008 at 7:27 am
Yes. It should be separate item
July 9, 2008 at 7:29 am
That actually violates the ANSI standard - look at the collation options, but I am not sure if you can get that to actually work.
July 9, 2008 at 7:34 am
I'm working in one migration from Oracle to SQL server and the Oracle has this feature and teh customer wants in SQL Server Also.
Any solution to this.
July 9, 2008 at 7:39 am
While COLLATE will take care of case sensitivity and the like, trailing white space is a huge PITA... I think anyone that depends on trailing white space is asking for trouble. 😉
That not withstanding, here's one way to do it...
DECLARE @String1 VARCHAR(20),
@String2 VARCHAR(20)
SELECT @String1 = 'Bala',
@String2 = 'Bala '
SELECT CASE
WHEN @String1 = @String2
AND DATALENGTH(@String1) = DATALENGTH(@String2)
THEN 'Match'
ELSE 'No Match'
END
--Jeff Moden
Change is inevitable... Change for the better is not.
July 9, 2008 at 7:46 am
Thanks Jeff.
But i need to store them as well in the primary key column.
Thanks and Regards
Bala
July 9, 2008 at 7:50 am
Right, so following Jeff's plan, a solution for your PK on the table would be to add an additional field that holds the length of the data in your column and make this part of a surrogate key. Another option, I suppose would be to add an additional character to the end of every item so your trailing space is actually container in the data (make "Joe " into "Joe ^" and "Joe" into "Joe^" and then strip off the extra character in the application.
Either way, you are really asking for trouble making keys that depend on trailing spaces. I would recommend you go back to your clients and try to convince them of the folly of their ways.
Viewing 15 posts - 1 through 15 (of 18 total)
You must be logged in to reply to this topic. Login to reply