This is an issue that I've put way too much time into.
I'm passing in a string as
@OrderString varchar(255) = '1=1;|2=|3=|4=1;|5=|'
The first number is the item I'd like to order I'll save that in @ItemNum the second number after the = is the quantity(will be stored as @ItemQuat) . The quantity can be anything from 1 to 1000. If zero is ordered then it will just be the item number and =.
The question is how can I dynamically pull these values? I only want the values that are greater then 0.
I've messed around with it for hours and I'm not sure if I have to update the logic that builds the string or is it possible to pull the correct values using string functions in sql.
Example of what I currently have:
--Obviously this won't work because it will always pull 1 regardless if the amount ordered is 0
set @ItemNum = substring(@OrderString, 1, charindex('=', @OrderString, 1)-1)
--This is currently wrong too because its pulling the quant for item 1
set @ItemQuat = substring(@OrderString, charindex('=',@OrderString,1)+1, charindex('|',@OrderString,1)-charindex('=',@OrderString,1)-1)
I'm looping through and concatenating the string after pulling the first value, etc.
Any help would be appreciated!