SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 why the update is failing
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aakcse
Aged Yak Warrior

India
517 Posts

Posted - 06/26/2012 :  07:58:20  Show Profile  Reply with Quote
select * from lp1 --only 1 colum LUM
--below is the data from column LUM



LUM
-------------------------------
AIX2 actuser1
+ actuser2
SOLARIS9 actuser4,actuser8


UPDATE LP1 SET lum = REPLACE(Lum,' ',',')

3 rows updated
select * from LP1

LUMP
-----------
AIX2 actuser1
+ actuser2
SOLARIS9 actuser4,actuser8

SELECT REPLACE('SOLARIS9 actuser4,actuser8',' ',',')
--SOLARIS9,actuser4,actuser8



Why the update is failing ? could anyone help

-Neil

Ifor
Constraint Violating Yak Guru

476 Posts

Posted - 06/26/2012 :  08:04:33  Show Profile  Reply with Quote
What is the result of:


SELECT ASCII(SUBSTRING(LUM, 9, 1)) AS ASCIIValue
FROM lp1
WHERE LUM LIKE 'SOLARIS%'


If it is anything other than 32, then the separator is not a space.
Go to Top of Page

aakcse
Aged Yak Warrior

India
517 Posts

Posted - 06/26/2012 :  08:09:07  Show Profile  Reply with Quote


SELECT ASCII(SUBSTRING(LUM, 9, 1)) AS ASCIIValue
FROM lp1
WHERE LUM LIKE 'SOLARIS%


Result is 9



-Neil
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
261 Posts

Posted - 06/26/2012 :  08:24:42  Show Profile  Reply with Quote
quote:
Originally posted by aakcse

select * from lp1 --only 1 colum LUM
--below is the data from column LUM



LUM
-------------------------------
AIX2 actuser1
+ actuser2
SOLARIS9 actuser4,actuser8


UPDATE LP1 SET lum = REPLACE(Lum,' ',',')

3 rows updated
select * from LP1

LUMP
-----------
AIX2 actuser1
+ actuser2
SOLARIS9 actuser4,actuser8

SELECT REPLACE('SOLARIS9 actuser4,actuser8',' ',',')
--SOLARIS9,actuser4,actuser8



Why the update is failing ? could anyone help

-Neil


It looks like it is not generating any Errors!!

Try this please
UPDATE LP1 SET lum = REPLACE(Lum,char(32),char(44))


luck,


--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8515 Posts

Posted - 06/26/2012 :  08:37:16  Show Profile  Visit webfred's Homepage  Reply with Quote
There is a TAB instead of a SPACE hence the update can't work as you want.

set lum=replace(replace(lum,char(9),','),' ',',')

should fix it


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
261 Posts

Posted - 06/26/2012 :  08:39:36  Show Profile  Reply with Quote
quote:
Originally posted by webfred

There is a TAB instead of a SPACE hence the update can't work as you want.

set lum=replace(replace(lum,char(9),','),' ',',')

should fix it


No, you're never too old to Yak'n'Roll if you're too young to die.



Yes, this is a good catch :)

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

aakcse
Aged Yak Warrior

India
517 Posts

Posted - 06/26/2012 :  08:47:21  Show Profile  Reply with Quote
Thanks Thats right when I pressed TAB instead of ' ' (Space) it worked.


-Neil
Go to Top of Page

aakcse
Aged Yak Warrior

India
517 Posts

Posted - 06/26/2012 :  08:51:13  Show Profile  Reply with Quote
How to identify if it is a tab or space? Tab also has spaces in it, does tab differs from other tab, as I have noticed some tabs have 1 space and other 2,3 etc.. are they all same?

-Neil
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
261 Posts

Posted - 06/26/2012 :  09:07:16  Show Profile  Reply with Quote
quote:
Originally posted by aakcse

How to identify if it is a tab or space? Tab also has spaces in it, does tab differs from other tab, as I have noticed some tabs have 1 space and other 2,3 etc.. are they all same?

-Neil



in MS SQL you can identify the the ASCII code for any character by executing:
SELECT ASCII(any character)
e.g
SELECT ASCII(' ')
result:
32.

white spaces are different from each other, but there's only one ascii code that represent either space, tab, new line...etc.

Luck,

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000