A Sql Query To Select Two Substrings From A Known String
I need a SQL query to get two charstrings from one main string, the returned values start with T#######@@###@@####. The main string length changes. Example: Main string @code=0251
Solution 1:
Try this on, This will select complete list of substrings in your main string
declare@myString nvarchar(500)='025121710TestPASS*68242850AD*68242382AF*1UJ97DX9AF*68248793AB*68236772AB*56054275AG*NoPN*1UW38DX9ACNoPNT00BE161571394 *T8LQI141529458*NoPNNoPNNoPN*NoPN'
;with T(ind,pos) as (
select charindex('T', @myString), 1unionallselect charindex('T', substring(@myString,ind+1,len(@myString)))+ind,pos+1from t
where pos >0and ind <> charindex('T', substring(@myString,ind+1,len(@myString)))+ind
)
selectsubstring(@myString,ind,14) as YourString from t wheresubstring(@myString,ind,14) NOTLIKE'%[^a-zA-Z0-9]%'
Post a Comment for "A Sql Query To Select Two Substrings From A Known String"