---
title: "How to get all optional parameters from SQL Server"  
description: "How to get all optional parameters from SQL Server"  
author: "Anonymous User"  
published: 2014-11-04  
updated: 2014-11-04  
canonical: https://www.mindstick.com/forum/2508/how-to-get-all-optional-parameters-from-sql-server  
category: "c#"  
tags: ["api(s)", "sql server", "web"]  
reading_time: 2 minutes  

---

# How to get all optional parameters from SQL Server

I am creating a [Web API](https://www.mindstick.com/articles/324352/how-to-create-web-api-in-dot-net-core-3-1-mvc) GET (all) [method](https://www.mindstick.com/forum/166/webservice-method) with [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) [optional](https://www.mindstick.com/interview/22851/main-difference-between-optional-and-required-keywords) parameters. I'm trying this with 1 [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) first but eventually, I want 5 optional parameters. [Starting](https://www.mindstick.com/blog/12024/things-you-need-to-know-when-starting-your-own-business) with 1 parameter I have 2 situations: parameter is filled in and parameter is not filled in.

Parameter is filled in

```
from r in db.requests
where r.status == status
select new Models.Request
```

Parameter is not filled in

```
from r in db.requests
select new Models.Request
```

I can not get both situations to work [together](https://yourviews.mindstick.com/view/80819/live-in-relationship-protecting-the-right-to-live-together) so my [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) is: How can I [combine](https://www.mindstick.com/interview/1043/how-can-i-combined-two-variable-together) these 2 situations?

**[Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc)**

```
public IEnumerable<Request> Get(string status = "")
    {
        var requests = from r in db.requests
                       //where r.status == status
                       select new Models.Request
                       {
                           ID = r.ID,
                           ...more properties
                           };
            return (IEnumerable<Request>)requests;
    }
```

## Route

```
protected void Application_Start()
    {
        RouteTable.Routes.MapHttpRoute(
        name: "API Default",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional });
    }
```

## Replies

### Reply by Anonymous User

Try the following code:

```
from r in db.requests
where r.status == status || status == ""
select new Models.Request
```

If the status is empty string second part of the expression is true and all items will be returned no matter the value of the first part. Otherwise, the first part of the expression filters the result set.


---

Original Source: https://www.mindstick.com/forum/2508/how-to-get-all-optional-parameters-from-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
