I have a couple of custom queries in the simpleproduct xml package. The first works great, and I'm able to display several custom fields that were created in the product variants table.

What I need to do is use a field value from the first custom query (value of field CUSTCHAR21) in the second query so the database will return other products in the database that share the same value.

How do I get that value so I can use in the query: SELECT WHERE (value of CUSTCHAR21) = CUSTCHAR21?

<!-- Query to show product variant table fields - Only one variant allowed for these products -->
<query name="Variants" rowElementName="Variant">
<sql>
<![CDATA[
SELECT * FROM ProductVariant PV WITH(NOLOCK)
WHERE PV.ProductID = @ProductID
AND PV.Published = 1 AND PV.Deleted = 0 AND PV.IsDefault = 1
]]>
</sql>
<queryparam paramname="@ProductID" paramtype="request" requestparamname="ProductID" sqlDataType="int" defvalue="0" validationpattern="^\d{1,10}$" />
</query>

<!-- Query to show related products in group -->
<query name="GroupItems" rowElementName="Product" runif="showproduct">
<sql>
<![CDATA[
SELECT * FROM ProductGroup WITH(NOLOCK)
WHERE CUSTCHAR21 = @ (Value of CUSTCHAR21 in the first query)
]]>
</sql>

<queryparam paramname="@???" paramtype="request" requestparamname="???" sqlDataType="varchar" defvalue="0" validationpattern="" />
</query>