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)
 SUBSTRING

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-07-15 : 11:43:20


I have the following in a column. i would like to seperate them

00577|4075402888
00576|4075402886
03830|4075402599
06366|4075402680
|8554770449
06800|4075407794
00493|4075407672


ANYTHING FROM THE LEFT OF | SHOULD BE RETURN IN MY QUERY
AS LONG AS THERE ARE NUMBBERS example
06366|
00576|
03830|
06800|.
00493|

I can get the other using right(numbers,11) as 'some number' which will return
|8554770449

please advise

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-07-15 : 11:53:47
You should be able to use LEFT function in a similar way - eg.
LEFT(numbers,CHARINDEX('|',numbers)-1);
If you want to suppress the row that has the blank, use a where clause as in
WHERE LEFT(numbers,CHARINDEX('|',numbers)-1) <> ''
Go to Top of Page
   

- Advertisement -