I want to delete using INNER JOIN in SQL Server 2008. But I get this error: Msg 156, Level 15, State 1, Line 15 Incorrect syntax near the keyword ‘INNER’. My code: Answer You need to specify what table you are deleting from. Here is a version with an alias:
Tag: sql-server-2008
SQL “between” not inclusive
I have a query like this: But this gives no results even though there is data on the 1st. created_at looks like 2013-05-01 22:25:19, I suspect it has to do with the time? How could this be resolved? It works just fine if I do larger date ranges, but it should (inclusive) work with a single date too. Answer It
How to find third or nᵗʰ maximum salary from salary table?
How to find third or nth maximum salary from salary table(EmpID, EmpName, EmpSalary) in optimized way? Answer Use ROW_NUMBER(if you want a single) or DENSE_RANK(for all related rows):
SQL SERVER: Check if variable is null and then assign statement for Where Clause
I am trying to achieve something like the below in WHERE clause in sql. I tried the following: which is wrong. Can anyone help in framing the exact statement. Thanks! Answer Isnull() syntax is built in for this kind of thing. For your example keep in mind you can change scope to be yet another where predicate off of a
Null or empty check for a string variable
I want to know whether the above piece of code works in checking if the variable is null or empty. Answer Yes, that code does exactly that. You can also use: Edit: With the added information that @value is an int value, you need instead: An int value can never contain the value ”.
How to kill/stop a long SQL query immediately?
I am using SQL server 2008 and its management studio. I executed a query that yields many rows. I tried to cancel it via the red cancel button, but it has not stopped for the past 10 minutes. It usually stops within 3 minutes. What could the reason be and how do I stop it immediately ? Answer What could
Update only time from my Datetime field in sql
I have a date 2013-12-14 05:00:00.000 in my table. Now i want to update only time of that date. E.G to 2013-12-14 04:00:00.000 Is there any query to update only time from datetime field? Answer Or this
SQL Server – Create a copy of a database table and place it in the same database?
I have a table ABC in a database DB. I want to create copies of ABC with names ABC_1, ABC_2, ABC_3 in the same DB. How can I do that using either Management Studio (preferably) or SQL queries ? This is for SQL Server 2008 R2. Answer Use SELECT … INTO: This will create a new table ABC_1 that has
Updating a Table after some values are inserted into it in SQL Server 2008
I am trying to write a stored procedure in SQL Server 2008 which updates a table after some values are inserted into the table. My stored procedure takes the values from a DMV and stores them in a table. In the same procedure after insert query, I have written an update query for the same table. Insert results are populated
How to convert a loop in SQL to Set-based logic
I have spent a good portion of today and yesterday attempting to decide whether to utilize a loop or cursor in SQL or to figure out how to use set based logic to solve the problem. I am not new to set logic, but this problem seems to be particularly complex. The Problem The idea is that if I have