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
 Substring

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2010-02-10 : 06:49:15
Does anyone know of a substring capability in SQL

I have a field with the below examples
Hull(North)
Newport(Hants)

The only thing I would like returned is
Hull
Newport

Any ideas

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2010-02-10 : 06:53:39
select substring(col, 1, charindex('(', col) -1) from tbl

Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2010-02-10 : 06:56:15
I get incorrect syntax with substring :(
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-02-10 : 06:56:31
select left(your_column,charindex('(',your_column)-1)


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

msuneerbabu
Starting Member

6 Posts

Posted - 2010-02-10 : 06:57:10
SUBSTRING ( expression , start , length )
EX:
SELECT LastName, SUBSTRING(FirstName, 1, 1) AS Initial

if you dont knw abt the start/length of the string, use 'Replace'

like "SELECT REPLACE(Column_Value,'(%)','');


Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2010-02-10 : 06:57:53
Hold on, typing error, It works

Harsh Athalye you are a genius, thank you very much.
Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2010-02-10 : 06:58:27
thank you all for your help.

SQL TEAM forum is the best!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-02-10 : 06:58:36
quote:
Originally posted by godspeedba

I get incorrect syntax with substring :(


Post the statement that errors please.


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

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-02-10 : 06:59:07
Ooh - ok


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

- Advertisement -