Suppose I have 2 variables that look like an array:
declare @code nvarchar(200) =
',10501,10203,10491,10490,10091,10253,10008,10020,10570,10499,';
declare @value nvarchar(200) =
'True~~100000006~Digital~0~0~~1388.76~Completed~True';
I need to find if @code
contains 10490
(for example) and if it does, I need to find a corresponding value (by its index) in @value
variable which would be Digital
since 10490
is the 4th element in @code
array and 4th element of @value
array is Digital
(note that the 2nd element of the @value
array is NULL.
Disclaimer:
@code
array will ALWAYS contain unique values. It's not possible to have more than 1 10490
for example.
@code
array will always start and end with ','.
Number of elements in @code
and @value
will always be the same if you take 1st and last comma off the @code
variable.
I cannot use functions or stored procedures, so everything needs to be done as part of 1 query.