Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SP

Status
Not open for further replies.

mayu03

Programmer
Oct 3, 2003
91
US
Is it possible to do in one statement?
I have a sp where I am passing 2 param:
@lastName and @ID. Some times ID can be empty and I
need to select based on lastname, if Id is not empty select
spesific record. My 'or' and 'And' is not working correct.
Can you help me?
SELECT *
FROM Table1
WHERE NameLast LIKE @lastName or ID='@id
 
How about this:

Code:
SELECT *
FROM  Table1
WHERE (
   (@id IS NOT NULL AND ID = @id)
   OR
   (@id IS NULL AND NameLast LIKE @lastName)
      )

--Angel [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top