Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 spaces in front of ID

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-01-24 : 17:02:32
I have a table looks like:


ID
0890
0986
08976
019908
76543

I would like to get rid of spaces in front of ID and leave '0'.

The output should looks like:

ID
0890
0986
08976
019908
76543


How can i do this?




nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-24 : 17:06:49
see ltrim in bol.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-01-24 : 17:10:36
I’ve used ltrim function ,but it doesn’t recognized as spaces. What could be the reason?



Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-24 : 17:15:25
It works with LTRIM, perhaps your data is different:


DECLARE @ID varchar(10)

SET @ID = ' Tara'

PRINT @ID
PRINT LTRIM(@ID)


Tara
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-24 : 17:25:10
Sounds like it's not a space
try
select substring(ID, patindex('%[0-9]%',ID), 20)
from tbl


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -