Monday, March 2, 2020

To write Case Statement in WHERE Clause

 DECLARE @FirstName VARCHAR(100)
SET @FirstName = 'King'

DECLARE @LastName VARCHAR(100)
SET @LastName = 'Test'

SELECT FirstName, LastName
FROM Employee
WHERE 
    FirstName = CASE
    WHEN LEN(@FirstName) > 0 THEN  @FirstName
    ELSE FirstName
    END
AND
    LastName = CASE
    WHEN LEN(@LastName) > 0 THEN  @LastName
    ELSE LastName
    END
GO

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...