Skip to content

Tag: sql-server

Compare two tables via the three tables SQL

I plan to compare two tables via the three table. my query is as the following if the count is zore, then the tableA and TableC match, otherwise, these two tables do not match It takes a long time to run the query. Do we have a way to compare tableA and tableC fast? Question: How to compare tableA and

Add rows accumulated by current month

Is there a way to translate my hard coded SQL script into a dynamic? My problem with this code is that, it still adding the SEPT-DEC it should be zero since we are not yet covered this month My table Expected Result: Starts from JAN then Added the succeeding covered months. Answer You can UNPIVOT your data, u…

sql selecting unique rows based on a specific column

I have an table like this : I am trying to filter out something like this based on Col1 I am trying to get the all unique rows based on the values in Col1. If I have duplicates in Col1, the first row should be taken. I tried SELECT Col1 FROM tblname GROUP BY Col1 and got unique Col1 but

SQL DATEPART(qq, @date) date quarter start October

I have a query that prints the data grouped quarter, the query uses datepart(qq,repo.lesson_date) SQL function. My issue is I want my first quarter to be October-December and not Jan-March like the output I get from the SQL function above. Is there anyone can assist? Answer You may use an additional calculati…

SQL Query for the player and vsplayer [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question Team Table Expected Output: with Two columns How to write a sql query to get the exact output …

Round to nearest 15 minute interval

I’ve seen this question asked and answered for time that is stored as a date, but I have duration of hours and minutes stored as numeric(4,2). For example 2.12, is 2 hours 12 minutes. I need to round that to the nearest 15 minute interval, doing this (CONVERT([numeric](4,2),round(2.12/(25),(2))*(25))) d…

Merging Rows and put values in different columns

I have the following table: and want to get to this result: An ID value in the first table occurs max 4 times: Booked + 1 = was either marked booked the first time in database OR was either marked booked the last time in database Booked + 0 = was either marked not-booked the first time in database OR