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
 General SQL Server Forums
 New to SQL Server Programming
 delete first word before "space" in cell of column

Author  Topic 

ramsis
Starting Member

2 Posts

Posted - 2010-09-16 : 08:58:19
Hope you can help me on this:

SQL server 2003

i have a column where i'd like to remove/delete the first word before "space" in each field of a column.
how can i do this?

for example: (skimmed milk 1L) to be (milk 1L)

thanx,
ramsis

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-09-16 : 09:02:30
Try this

Select right('skimmed milk 1L',len('skimmed milk 1L')-charindex(' ','skimmed milk 1L'))

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-16 : 12:28:07
quote:
Originally posted by ramsis

Hope you can help me on this:

SQL server 2003

i have a column where i'd like to remove/delete the first word before "space" in each field of a column.
how can i do this?

for example: (skimmed milk 1L) to be (milk 1L)

thanx,
ramsis


there's no 2003 version for SQL Server. May be you meant 2005

anyways you can try the below:-

select stuff('skimmed milk 1L',1,charindex(' ','skimmed milk 1L'),'')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ramsis
Starting Member

2 Posts

Posted - 2010-09-18 : 07:32:04
many thanx for your help, i highly appreciate that!

it worked with me like that:

UPDATE dbo.tblstsabit
SET stok_adi=right(stok_adi,len(stok_adi)-(charindex(' ',stok_adi)-1))

but now there are ' 'spaces left before. is there a function like 'trim()' in SQL Server2005?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-18 : 07:36:18
LTRIM(right(stok_adi,len(stok_adi)-(charindex(' ',stok_adi)-1)))


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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-18 : 08:59:11
quote:
Originally posted by ramsis

many thanx for your help, i highly appreciate that!

it worked with me like that:

UPDATE dbo.tblstsabit
SET stok_adi=right(stok_adi,len(stok_adi)-(charindex(' ',stok_adi)-1))

but now there are ' 'spaces left before. is there a function like 'trim()' in SQL Server2005?


you've LTRIM and RTRIM for trimming leading as well as trailing spaces

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -