Lajja Thaker
Lajja Thaker

Reputation: 2041

where clause in SQL

I have dropdownlist which having records 'All','A','B','C' .

On click event of button I am fetching records from database through Stored Procedure.

My sql query which is in stored procedure :

Select * from TableA where Name = @Name

here @Name is parameter which I have passed to stored procedure whose value is selecting from dropdownlist.

If I am selecting 'A' from dropdownlist my query will be

Select * from TableA where Name = 'A'

but my question is if I am selecting 'All' then I want records like

Select * from TableA

How can I execute that in single statement of query? I dont want to use If.. else condition in stored procedure.

Upvotes: 1

Views: 1194

Answers (3)

Abhinav
Abhinav

Reputation: 2085

Select * from TableA where ((@Name = 'All') OR (Name = @Name))

Upvotes: 3

Ivo
Ivo

Reputation: 8352

Select * from TableA where Name = @Name or @Name = 'All'

Upvotes: 0

yogi
yogi

Reputation: 19591

Try this

select *  
from A 
where @Name = 'All' or Name = @Name

Upvotes: 1

Related Questions