Home > DeveloperSection > Forums > Selecting specific records in a column else all of them
Kate Smith
Kate Smith

Total Post:24

Posted on    October-16-2013 6:46 AM

 C# C# 

 1 Reply(s)
 668  View(s)
Rate this:

I am building a website in ASP.NET with SQL Server 2012 use in back end.

And I also have drop down boxes that contain the following strings as an example.





What sort of SQL command do I need to in order to be able to use logic like this pseduo.

If SelectedItem is 'abc' return all rows in column


Retrieve records in column where alphabet_text = ListItem.

I dont want to use a simple IF ELSE stored procedure because I have lots and lots of filtering options available and making else seems really badly designed.

Andrew Deniel
Andrew Deniel

Total Post:29

Posted on    October-16-2013 7:37 AM

Use WHERE with OR:

SELECT IdCol, TextCol

FROM dbo.Table

WHERE @TextCol = 'Doesnt matter' OR TextCol = @TextCol

On this way TextCol will only be evaluated if the paramater is different than Doesn't matter.

Note that i've used the text value just for demontsration purposes. You should use the IdCol instead since(text can change anyway).

Don't want to miss updates? Please click the below button!

Follow MindStick