[Solved] sql qry trickl puzzle


SELECT *

FROM @tblA

WHERE

@ColA = ColA AND

(@ColB = ColB) AND

(@ColC = ColC)

Union

–Handles direct or wrong input values

SELECT *

FROM @tblA CPT

WHERE

@ColA = ColA and

(EXISTS(SELECT 1 FROM @tblA WHERE @ColB=ColB) and @ColB is Not NULL and @ColB =
ColB)

Union

–Handles direct or wrong input values

SELECT *

FROM @tblA CPT

WHERE

@ColA = ColA and

(EXISTS(SELECT 1 FROM @tblA WHERE @ColC=ColC) and @ColC is Not NULL and @ColC = ColC)

Union

–Handles direct or wrong input values

SELECT *

FROM @tblA CPT

WHERE

@ColA = ColA and

(@ColB not in (SELECT ColB FROM @tblA) and @ColB is Not NULL and 

ISNULL(ColB, @ColB)= @ColB)

Union

–Handles NULL input values

SELECT *

FROM @tblA CPT

WHERE

@ColA = ColA and

@ColB is NULL and ISNULL(ColB, @ColB)= @ColB 

solved sql qry trickl puzzle