Skip to content

Tag: sql-server

Conditional Order By in sql server with multiple order columns

i wish to perform conditional order by with multiple columns i am expecting a query like can we achieve this.? sample data result i need is Answer I think this is what you want: Appreciate that when price is NULL, the above reduces to: That is, the alternate CASE expressions just collapse to NULL, leaving the…

SQL. full range of dates for every user

Please see code below. For every Underwriter that exists that is in a given month, I need every single date in the month and the given Underwriter. Thank you so much Original Table: Desired Output: Please note that Rebecca should not have dates for 12/1/2019 to 12/31/2019 Attempted Code Answer Use a Tally, th…

Try to define a left join only with where condition

I try to find a particular SQL statement to replace an old SQL query. To summarize, I try to make a left join only with where conditions. Here is my test environment: I fill the tables with some data: The usual way for a left join is this: This query returns 1266 rows. But in the old application, which I