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 2012 Forums
 Transact-SQL (2012)
 extract part of a text field

Author  Topic 

wided
Posting Yak Master

218 Posts

Posted - 2013-01-30 : 05:24:57
Hello

how to extract part of a text field as follows:

Field1 = '7589-05 '
or
Field1 = '10589-06 '

I would like to extract the data before (-):

7589 and 10589

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-30 : 05:28:10
LEFT(Field1,CHARINDEX('-',Field1+'-')-1)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
Go to Top of Page

wided
Posting Yak Master

218 Posts

Posted - 2013-01-30 : 06:19:45
thanks it is ok
Go to Top of Page
   

- Advertisement -