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
 Sql Substring

Author  Topic 

daniel50096230
Yak Posting Veteran

99 Posts

Posted - 2011-04-05 : 04:45:21
Hi,

I have an id something like 'TEFS_10-1-1'

How should I write my sql so that it will match the id with those number after "_" in above id? I know I can use substring, but the problem is the character before "_" is not fix.

Eg.

ON T.Reference_ID = A.Reference_ID Where A.Reference_ID is '10-1-1' but not 'TEFS_10-1-1'. So how can I filter out those character before "_"

matty
Posting Yak Master

161 Posts

Posted - 2011-04-05 : 05:06:27
SELECT SUBSTRING(Reference_ID ,CHARINDEX('_',Reference_ID ) + 1,LEN(Reference_ID ))
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-05 : 07:39:09
or

select parsename(replace(col,'_','.'),1) from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -