---
title: "Selecting specific records in a column else all of them"  
description: "Selecting specific records in a column else all of them"  
author: "Kate Smith"  
published: 2013-10-16  
updated: 2013-10-16  
canonical: https://www.mindstick.com/forum/1686/selecting-specific-records-in-a-column-else-all-of-them  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Selecting specific records in a column else all of them

I am [building](https://www.mindstick.com/blog/23088/which-tonewood-is-suitable-for-building-a-guitar) a [website](https://www.mindstick.com/articles/13110/why-copywriting-is-crucial-for-new-website-build) in ASP.NET with [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) 2012 use in back end.

And I also have [drop down](https://www.mindstick.com/forum/263/drop-down-list-problem) boxes that contain the following strings as an example.

<asp:[ListItem](https://www.mindstick.com/forum/23267/insert-a-listitem-to-a-dropdownlist)>abc</asp:ListItem>

<asp:ListItem>zyz</asp:ListItem>

<asp:ListItem>dood</asp:ListItem>

<asp:ListItem>foo</asp:ListItem>

What sort of [SQL command](https://www.mindstick.com/blog/142/categorize-sql-commands-in-sql-server) do I need to in order to be able to use logic like this pseduo.

If SelectedItem is 'abc' return all rows in column

ELSE IF

[Retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) records in column where alphabet_text = ListItem.

I dont want to use a simple IF ELSE stored [procedure](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) because I have lots and lots of [filtering](https://www.mindstick.com/forum/33958/how-to-filtering-with-the-entity-framework-is-an-asp-dot-net-mvc-application) [options available](https://www.mindstick.com/forum/158610/discuss-the-various-authentication-and-authorization-options-available-in-dot-net-core) and making else seems really badly designed.

## Replies

### Reply by Andrew Deniel

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).


---

Original Source: https://www.mindstick.com/forum/1686/selecting-specific-records-in-a-column-else-all-of-them

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
