> For the complete documentation index, see [llms.txt](https://wiki.owain.codes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.owain.codes/coding/snippets/untitled/build-up-sql-statements.md).

# Build up SQL statements

```
   var sql = scope.SqlContext.Sql().Select("*")
                        .From<DownloadsEntry>();
                    if (dateRange.From.HasValue)
                        sql.Where<DownloadsEntry>(d => d.DownloadDate >= dateRange.From.Value);
                    if(dateRange.To.HasValue)
                        sql.Where<DownloadsEntry>(d => d.DownloadDate < dateRange.To.Value);

```

Only works if you want AND clauses between the Wheres
