I have a table like this: And I need to forbid any rent time intersection for the same car. I found that, when a function is used (example below) inside the constraint, the value it returns is different from whent it is used outside the constraint. So when I’m trying to insert data into the table, the constraint would never
Tag: tsql
SQL: Query the same column 3 times with 3 different where clauses
Trying to show a table with 3 columns that are prices that need to be displayed. the columns are differentiated by ‘price_type’ and there are 3 different price types. Its probably something obvious …
LAG function with two different partitions
I have a table with multiple calendars inside it and I need to get the previous business day for each row in the table. I’ve been trying to use the LAG function to achieve this but I’m unable to get the correct return for every item. I’ve ended up splitting it into two queries. When the day is a business
Can I use string_split with enforcing combination of labels?
So I have the following table: Id Name Label ————————————— 1 FirstTicket bike|motorbike 2 SecondTicket bike 3 ThirdTicket e-bike|…
How to get the primacy of a function for an employee?
I have this following query to get all the functions and the related scopes (companies) for an employee : SELECT * FROM employee_scope WHERE EmployeeId=54 Output : EmployeeId FunctionId …
Split string values with various length spearated spaces into three columns
My tableA col1 has three values and separated by various length. I need to separate it and into three columns and place it into Z1, Z2, and Z3 respectively. Also, on some individual value has spaces …
How do I join a sparse table and fill rows between in SQL Server
How can I apply weights from a one table to another [Port] where the weight table has sparse dates? [Port] table [Weights] table So, I want to use the weights as if I had a full table like this below. i.e. change to new weight on first day it appears in [Weights] table: Answer You can use apply: outer apply
Need to group records by consecutive date SQL
I’m building a query in order to build consecutive dates which is create table #consecutivedates ( sgid nvarchar(max), metric nvarchar(max), targetvalue nvarchar(max), startdate …
How to get the current month and previous months for the previous year
I have requirements to get the current month of the year and the last year’s month. Something like this: Right now what I did is hard code it like this: , ISNULL(SUM(CASE WHEN month(trans.DocDate) = …
List all teams and the average raw scores for all members
My query is giving all the teams the exact same average player score. When each team would should have their own average score based on their team members. select Teams.TeamName, avg(Bowler_Scores….