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
 delete first word before "space" in cell of column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ramsis
Starting Member

Egypt
2 Posts

Posted - 09/16/2010 :  08:58:19  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 09/16/2010 :  09:02:30  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
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

India
52249 Posts

Posted - 09/16/2010 :  12:28:07  Show Profile  Reply with Quote
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

Egypt
2 Posts

Posted - 09/18/2010 :  07:32:04  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8683 Posts

Posted - 09/18/2010 :  07:36:18  Show Profile  Visit webfred's Homepage  Reply with Quote
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

India
52249 Posts

Posted - 09/18/2010 :  08:59:11  Show Profile  Reply with Quote
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
  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.09 seconds. Powered By: Snitz Forums 2000