I have a table with the column as below, lets call the table Incident: IncidentId, IncidentType, StartDate, EndDate I need to find the EndDate of the previous Incident based on the nearest previous …
Tag: sql-server
Converting Queries into SQL Server syntax
I’ve been getting help from Chegg and most answers given to me don’t work for me. My first task is write a query where it list the employee assigned to the most projects. One response was: select …
SQL Finding multiple combinations in 2 tables (with all records)
I have two tables, one with some user configurations (#USERCONFIG) and the other (#COMBINATIONS), multiples combinations of configurations I need to find in the first table. With this example data, I want the resultset to look like this: Where it will return all users that have a match of configurations from …
Updating empty cells with filled cells values in duplicate records without unique key
I have a table tblPhone which contains duplicate records. E.g. As you are seeing above sample table have two duplicate records without uniquely identified KEY. Question 1 is: How I can uniquely identify each duplicate record in table? See the Note column which has NULL value in first row and Valu some values …
Add new key with value = NULL to existing JSON object
I have the following simple JSON object: I’d like to add a new key under application called “approve_date” and would like the value to be NULL. Is there a way to do this with JSON_MODIFY. I tried using ‘append’ in the path but this added an array, not a key (example below). What …
SQL optional parameter
I’m struggling to set optional parameter in MS SQL 2017. It should do: If parameter is null, then ignore the condition, but apply other conditions If parameter is set, then apply the condition …
UPDATE with INNER JOIN on SQL Server
I have 2 tables Users and Orders. Primary key of Users is UserId, which I have defined as foreign key in the Orders table. I have added a new column of UserName to Orders. I want to import UserName …
SQL group by is bringing lots of duplicates
I’m trying to group my data by OccDate, ParkingContextType, AuthorityId and of course, i would like to measure each sessions for each date/contexttype etc… However, I`m also trying to calculate the …
SQL – a member can see a doctor only once a year
I have a table named Claim. I have built the following query except the last column(Reimburse). How do I populate Reimburse column like this table? So the idea is that company pays a member to see a …
How to store code/programs written in any programming language in SQL Server
I have to display some C# code on a page of my web application (ASP.NET MVC application). How can i store C# code (program) in SQL Server ? Consider that i have the following code: public class …