I would like to retrieve the value inside a Text. Here is my example:
<Host_In_Params>{"Zip_Code":"94941"}</Host_In_Params>
How can I easily get the result 94941
from the above string value?
I would like to retrieve the value inside a Text. Here is my example:
<Host_In_Params>{"Zip_Code":"94941"}</Host_In_Params>
How can I easily get the result 94941
from the above string value?
You can use Json function
SELECT
'{"Zip_Code":"94941"}'
,JSON_VALUE('{"Zip_Code":"94941"}', '$.Zip_Code') AS YourValue
Here is a second idea: (Quick and Dirty)
DECLARE @test varchar(100);
SELECT @test = '<Host_In_Params>{"Zip_Code":"94941"}</Host_In_Params>';
SELECT SUBSTRING(
@test
,CHARINDEX('Zip_Code', @test) + 11
,5
);
Based on the question the answer is
DECLARE @CODE VARCHAR(50)
SET @CODE = '{"Zip_Code":"94941"}'
SELECT @CODE
SELECT REVERSE(SUBSTRING (REVERSE(@CODE), CHARINDEX('"', @CODE) +1 , 5))
This completely varies based on the data in the @code
.