OPENROWSET does not accept variables for its arguments (SQL Server)

If you’re trying to use OPENROWSET to run an ad hoc distributed query in SQL Server, but you keep getting an “incorrect syntax” error, and you just can’t see anything wrong with your syntax, it could be that you’re trying to use a variable for one of the arguments.

As mentioned in the title of this post, OPENROWSET does not accept variables for its arguments.

If you’re using variables as arguments, try changing these to string literals.

Continue reading

How to Fix “Procedure expects parameter ‘@statement’ of type ‘ntext/nchar/nvarchar’.” Error in SQL Server

It’s quite easy to encounter error Msg 214, Level 16 when executing stored procedures such as sp_executesql or sp_describe_first_result_set.

Fortunately it’s easy to fix too!

The most common reason for getting this error is that you forgot to prefix your string with N.

Therefore, to fix this issue, try prefixing your string with N.

Continue reading

Fix “index name must be a string” when Dropping Multiple Indexes in MongoDB

If you encounter the “index name must be a string” error when dropping multiple indexes in MongoDB, it’s probably because you’re passing the specifications document instead of the name.

When you use the dropIndexes() method or the dropIndexes command to drop multiple indexes, you need to pass the index names (not the specifications documents) in an array.

Continue reading

ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator (SQL Server)

If you’re running a query in SQL Server, and you get the following error…

Msg 104, Level 16, State 1, Line 8
ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.

…you should check your SQL statement – you’ve probably omitted a column from your SELECT list.

As the error message implies, you’ll probably only see this error if you’re running a query that contains a UNION, INTERSECT or EXCEPT operator.

Simply adding the column to your SELECT list should fix the problem.

Continue reading

How to Fix “The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION” in SQL Server

If you’re receiving error Msg 3902, Level 16, which reads “The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION”, it’s probably because you’ve got a stray COMMIT statement.

You could be getting this due to implementing error handling, and forgetting that you’ve already committed or rolled back the transaction elsewhere in your code.

Continue reading