Skip to content

Tag: sql-server

Why is my SQL query executing indefinitely?

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 …

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

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…

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…

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