ThisSELECT * FROM @LCS ) Q UNPIVOT ( [value] FOR [type] IN ( Q.pgifc1, Q.pgifc2, Q.pgifc3, Q.pgifc4 )
unpivots the data. From the data generated, this querySELECT R.* FROM ( SELECT * FROM @LCS ) Q UNPIVOT ( [value] FOR [type] IN ( Q.pgifc1, Q.pgifc2, Q.pgifc3, Q.pgifc4 ) ) R WHERE NOT R.[value] IS NULL
will filter the resultset with [vale] is not null. R is a alias name for the derived table.This following code uses the above as datasource and filter the data with code=@SearchForItems AS ( SELECT * FROM UnpivotData WHERE Code = @SearchFor )
MadhivananFailing to plan is Planning to fail