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 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy