It seems that this code is correct and I am not sure why it is not executing. I thought it might be extremely inefficient but after 15 minutes it is still executing. edit: Thank you all for the input. Answer You are using implicit CROSS JOIN in your query and this can kill your performance if you don’t …
Tag: sql-server
Query to Identify Above Average Sales for Company
I am trying to find the employees who have sales figures that are above the average sales totals for a particular company. I am using Microsoft SQL Server, and here is what I have so far: However, my query returns nothing. Is this the correct way to write something like this? What could I do to simplify thing…
Linq Find the most recurring record
I have a rent a car project. This is the table where I keep the rented vehicles I want to find the most rented vehicle in this table. How can I do this? So I want to find the most mentioned car Id in the table [I have to do it with context architecture. How can I do this with
How to use a variable with multiple values as a parameter in the where clause sql
I am trying to create a “where clause” that can handle multi-valued parameter but not getting it to work. With the above sample table I wish to create a query that filters the rows with colors red and blue using a variable parameter like the following: I tried using the STRING_SPLIT function but d…
Add column to table with existing data in SQL Server
I have a table Rates with data in it and I need to add new column to the table however I get the error: ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the prev…
How to select students with marks in all three subjects less then 100
I came across this question Here is my response to it, I just started myself learning SQL recently. Select a.roll_number , a.name , b.roll_number from student_information a join …
SQL in Excel: Cannot call declared variable
I am trying to breakdown my SQL string in Excel VBA, storing my variables in the first part of the SQL, and calling them in the second part. It seems that declared variables is not my friend here? First part(Declaring my variable) Second part(Calling my variable) Using a temp table works: But calling the vari…
Using a table as input parameter for sp_execute_remote (Azure SQL Database)
I am trying to use a table as input parameter for sp_execute_remote (Azure SQL Database). I declared the type on the remote db: I try to execute the script on my local db: I get an error on the 3rd EXEC statement: The underlying error message received was: ‘Operand type clash: int is incompatible with M…
CASE WHEN with GROUP BY
I have the following query : I get this following error : Column ‘Status’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Answer
Get rows of Last hour, Last ‘x’ minutes in SQL Server
Order ID Picker ID Time_Picked 1 111 2020-01-13 11:28:00 2 222 2020-01-13 11:40:00 3 333 2020-01-13 10:00:00 4 444 2020-01-13 9:00:00 5 555 2020-01-13 9:45:00 SELECT * FROM mytable WHERE …