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!

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)

Got it!

WHERE 
        ID like Case @strID when '' Then '%%' Else @strID End
        AND Name like Case @strName when '' Then '%%' Else @strName End
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.