I want to generate a list of columns using generate_series() and joining it to a specific array (a list of value, e.g. [1, 2, 3]), and my expected result looks like this: Day | Code 2019-08-01 …
How to number rows according to values in columns
Imagine I have an event log (ordered by UserID and Start, Start_of_previous_event is added using LAG(), inactive time = Start – Start_of_previous_event): UserID Event Start …
Update a Table Variable Where Not Exists
UPDATE @Customer SET ValidaitonAction = 1 WHERE NOT EXISTS (SELECT 1 FROM DMScustomerupload WHERE AccountNumber = @Customer.AccountNumber) Where @Customer is a TABLE variable: DECLARE @…
SQL Server CASE Statement Evaluate Expression Once
I may be missing something obvious! Thanks in advance for any help. I am trying to use a CASE statement in an inline SQL Statement. I only want to evaluate the expression once, so I am looking to put …
Clean up ‘duplicate’ data while preserving most recent entry
I want to display each crew member, basic info, and the most recent start date from their contracts. With my basic query, it returns a row for each contract, duplicating the basic info with a distinct …
Sql select from a table but use another table value as where clause [closed]
How can I select * from table posts but using table network_follow.follower as where condition? I have table posts, column by_user and table network_follow column follower I don’t know if that’s …
How to make a column describing order of elements?
I want to add a column to a table that describes the order of the rows by other value. For example, i have the following data: popularity = 1, id =1 popularity = 1, id =2 popularity = 2, id =3 …
Joining two tables and adding column values together
I have two tables, in both tables I have a unique column titled phone_number and then a column called spring with 3 others columns. The spring column has a number value. This table has about 3000 rows….
DbContext.DbSet.FromSql() not accepting parameters
I have a database with two tables, and wrote a relatively simple select statement that combines the data and returns me the fields I want. In my SQL developer software it executes just fine. Now to …
How to make a comparison for the record that has rows to another rows? [closed]
I have first table that has columns: 1. id 2. key 3. value And second table(more like the list): key I need to get distinct id that contains all keys from second table I have tried …