Categories: SQL Server

SQL Server Error : 116, Severity: 15. Only one expression can be specified in

SQL Server Error : 116 Details


SQL Server Error: 116
Severity: 15
Event Logged or not: No
Description:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Severity 15 Description:
Indicates syntax errors in the Transact-SQL command.

Example:

SELECT [ID], [Date], [Description], [Count] FROM [dbo].[Order] WHERE [ID] NOT IN (SELECT [ID], [NumberofStock] FROM [dbo].[Stock]) Msg 116, Level 16, State 1, Line 4 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

This error usually occurs when a sub-query is used in conjunction with the IN or NOT IN logical operator. The IN logical operator checks to see if a given value matches any value in a subquery or a list. The NOT IN logical operator is used to reject a subquery or list.

 

Solution for Resolving the Error

  1. One way to avoid this error is to follow the error message’s advice and use only one expression or column in the SELECT subquery statement.
  2. Another way to avoid this error is to rewrite the SELECT statement, using the EXISTS operator or the INNER JOIN when the IN operator is used, and the NOT EXISTS operator or the LEFT OUTER JOIN when the NOT IN operator is used.

In the case of the IN operator, the SELECT statement can be used to return all ID records that have corresponding records for Stock in Stock Table.

Because only unique ID records are required in the output, the DISTINCT clause can be included. If there are multiple ID records for a given ID record, the ID be returned multiple times in the output which is the need for the use of the DISTINCT clause.

The EXISTS operator can also be used to rewrite the SELECT statement that returns ID records that have corresponding ID records for Stock in Stock Table.

In the case of the NOT IN operator to be used, the SELECT statement can be used to return all ID  records that do not have corresponding ID records for Stock in Stock Table

SQL Server Error Code and solution summary


SQL Server Error: 116
Severity: 15
Event Logged or not: No
Description:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Make sure only one column is returned in “IN” Statement use and try rewrite query correctly.

Vamshi B

Recent Posts

sql server detected logical consistency based error

Learn about SQL Server detecting logical consistency based issues and how to resolve them.

5 months ago

sql server error 1222

Learn about SQL Server error 1222 and how to resolve the lock request time out…

5 months ago

Microsoft SQL Server 2022 New Features

Discover the new features of Microsoft SQL Server 2022 and how they compare to previous…

5 months ago

SQL Server Error 1222 lock request time out period exceeded

SQL Server Error 1222 lock request time out period exceeded   Lock request time out…

6 months ago

SQL Server Error : 427, Severity: 20. Could not load the definition for constr

SQL Server Error : 427, Severity: 20. Could not load the definition for constraint ID…

11 months ago

SQL Server Error : 204, Severity: 20. Normalization error in node %ls.

SQL Server Error : 204, Severity: 20. Normalization error in node %ls.

11 months ago

This website uses cookies.