0

I have 2 parameters

ID - txtID.text
Name - txtName.text

I would like to select (SQL):

SELECT
    ID
    ,NAME
FROM 
    TABLE
WHERE

If ID is not null read in txtID
If Name is not null read in txtName

If ID is null read all in select statement
If Name not null read all in select statement

Please help. Thank you!

2
Contributors
3
Replies
24
Views
4 Years
Discussion Span
Last Post by jaejoong
0
SELECT 
    ID
    ,NAME
FROM 
    TABLE1
WHERE
    ID = @strID
    and Name = @strName

How can I do,
If I choose ID without Name (it shows all ID)
If I choose Name without ID (it shows all Name)
If I choose both (it shows the data chose in the parameter)

0

Got it!

WHERE 
        ID like Case @strID when '' Then '%%' Else @strID End
        AND Name like Case @strName when '' Then '%%' Else @strName End
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.