Is it possible to get a the sum of value from the calendar_table to the main_table without joining like below? I am trying to avoid a join like this because main_table is a very large table with rows that have very large start and end dates, and it is absolutely killing my performance. And I’ve already …
Tag: sql-server
Insert rows into same table using data from different rows based on data from another table
I’ve got 2 tables: TimecardSetDetails, TimecardDetails TimecardSetDetails +————–+————-+————–+ | SetDetailsID | EmployeeKey | SetHistoryID | +————–+————-+—–…
how to resolve data type incompatability issue in SQL server
I have been trying to build below logic Declare @OT float Declare @Remark varchar(100) set @OT = 9.52 set @Remark = ‘1-25 hours’ select case when @Remark=’1-25 hours’ then (FLOOR((@OT * 100)/100)*…
How to delete row contain specific string on it in SQL Server
There are lots of rows that contain ’08:28:00.000′ in my table,like this one: I want to delete all the rows that ‘datetime’ contains ’08:28:00.000′.Instead of deleting this kind of rows one by one,is any command can delete all the rows than datetime contain ’08:28:00.…
How do I find a duplicate in SQL
I have a query that selects 3 columns. Each row row should be a unique combination of county, city,and zip. However, I have reason to believe I’m getting a duplicate somewhere. How do I find the …
How do you get the size of the gap from LEAD or LAG?
In my table, I have messages grouped by threads. Using LEAD, I can get the next message within a thread… [ThreadNextMessageId] = LEAD(gm.GroupMessageId, 1) OVER(PARTITION BY gm.ThreadId ORDER BY gm….
Count times date occurs between two dates in a second table
I have two tables [Charges] and [Defects] and want to produce [Desired Query Output] where the output counts the occurrances of defect when [Charges].ChargeDate is between (and including) [Defects].OpenDate and [Defects].CloseDate. For [Defects] table, a close date of NULL means it has not closed yet. Seems s…
After adding cursor to this query the execution time went from 10s to 2m.10s
I’m working on this query and after i added the bloc of cursor the execution time goes from 10s to 2m. Is there any way to reduce the execution time? The query is a result of 3 selects on the same table but with different conditions. I needed the cursor because I should get the price of an article from
SQL Join query with a null in Main table
Hi guys so in simple terms I have a Main table “A” and then another table “B”. All the data I want is basically from table A, but to figure one part out I need to join with B. My problem is although the column im joining with a column in B is correct, sometimes the column in A will
Case on Join condition
I have a two tables data as below table1: Order orderitem value O1 B-IV122 10 O2 B-IV144 10 table2: order Productionorder productionitem …