January 13, 2017 at 12:51 am
Hi,
how can extract the num Value from this String?. Num-Value can have var length.
Start: =
End: )
'#BAVDB#(RowCount=3204)'
Result: 3204
Regards
Nicole
January 13, 2017 at 3:44 am
DECLARE @String VARCHAR(50) = '#BAVDB#(RowCount=3204)';
-- As a single statement
SELECT NumVal = SUBSTRING(@String, CHARINDEX('=', @String) +1, CHARINDEX(')', @String, CHARINDEX('=', @String) +1) - CHARINDEX('=', @String) -1);
-- With a cte to identify the start and end positions
WITH ctePos AS (
SELECT
StartPos = CHARINDEX('=', @String)
, EndPos = CHARINDEX(')', @String, CHARINDEX('=', @String) +1)
)
SELECT NumVal = SUBSTRING(@String, StartPos +1, EndPos - StartPos -1)
FROM ctePos;
January 16, 2017 at 1:51 am
Try this :
DECLARE @String VARCHAR(50) = '#BAVDB#(RowCount=3204)';
SELECT REPLACE(Right(@String,LEN(@String)-CHARINDEX('=',@String)),')','')
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply