How do I merge two rows only if there is the TagWidgetIds are same but the tagValues are different?
You can first insert the results from the stored procedure into a temporary table (see https://stackoverflow.com/questions/653714/insert-results-of-a-stored-procedure-into-a-temporary-table), and then simply query that table with your conditions.  Let's say that you put the results in a temporary table called #procData.  In that case, your final query would look something like:

SELECT &lt;columns_you_want&gt;
FROM #procData p1
JOIN #procData p2
    ON p2.TagWidgetId = p1.TagWidgetId
    -- NOTE: if your columns are nullable, adjust this logic to account for that
    AND p2.TagValues &lt;&gt; p1.TagValues 
    AND p2.TagIndex &lt;&gt; p1.TagIndex 
    AND p2.ValueIndex &lt;&gt; p1.ValueIndex