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…
Tag: sql-server
Building table of unique sets
What I’m trying to do is build a table of unique sets of rows. What is the aim? I’m building an app for a service provider (let’s say cable company for example). Every customer has a set of …
Trying to Enter DateTime Data into Date Column, Date data is in two different formats
CREATE TABLE Customer_test ( customer_Id BIGINT NOT NULL, DOB DATE NULL DEFAULT ’01-01-1970′, Gender NVARCHAR(250) NULL, city_code NVARCHAR(250) NULL ) INSERT INTO …
SQL concatenate columns into string and only pull address
I have 4 fields that are address fields, but the address fields can be blank and have a persons name within one of the 4 fields. The name is usually before the start of the address. What I need to do is remove and names and empty string and only pull the core address or column that starts with a
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…
SQL : Only one expression can be specified in the select list when the subquery is not introduced with EXISTS
I tried query like this but i got message like Only one expression can be specified in the select list when the subquery is not introduced with EXISTS Code: Answer I guess you need below –
String Split String With multiple columns same separator
I have the following string ’06/30/2020;58044.373;.001;12/31/2020;58042.373;.003;06/30/2021;78044.373;.007′ I need to transform it into : col 1 col 2 col 3 —- —– –…
SQL Server : Stored Procedure for Preventing Duplicated Values
I have this code which I have created which I want to stop any duplicated values from being inserted into the database, however the values still continue to be able to get into the IF_Translations …
LEFT JOIN returning no results if a WHERE clause is added?
I’m trying to add the dbo.EmpHRSchedule.Type = ‘HOLIDAY’ entries to the Hours column only if they exist. To my understanding, a LEFT JOIN would only return entries if they match, and return NULL for non-matches. When I uncomment the AND ehrs.Type = ‘HOLIDAY’ line, no results are …
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