Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

If(something) then include in WHERE clause

$
0
0
Hi Would it be possible to do the following in TSQL stored procedure.

Quote:

SELECT STUDENTID, STUDENTNAME
FROM STUDENTS
WHERESTUDENTAGE = @STUDENTAGE
IF(STUDENTSEX<>null)
BEGIN AND STUDENTSEX = @STUDENTSEX
END
So if the "StudentSex" is null then leave it out of the where clause.

Viewing all articles
Browse latest Browse all 13329

Trending Articles