CFF KB - Carrz-Fox-Fire Promotions Knowledge Base

CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.
>>Development (Web and Desktop) >> Database >> SQL Server (Structured Query Language)

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Article ID: 215 - Date Created Sunday, April 02, 2017 - This Article Has been Viewed 232 times.
- Written By:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

CFF Knowledge Base - Share on MySpace CFF Knowledge Base - Share With Facebook CFF Knowledge Base - Share on Twitter CFF Knowledge Base - Share on Reddit CFF Knowledge Base - Share on Digg It CFF Knowledge Base - Share on Stumble Upon It CFF Knowledge Base - Share on Delicious
Share With Friends (Updated 6-8-2010)
Inner Select statements with two many expressions will cause an error.

Details
When creating an inner select statement inside of your existing select statement, you may sometimes add in two many columns, thus causing the following error to occur.

 
Msg 116, Level 16, State 1, Line 1

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.


Recreate Issue
To recreate this issue:

<%
Select (Select column1, column2 from table 1 where column1=table2.column1)as MyColumn, Table2.Column1, Table2.Column2
%>


In the above example, we see that there are two columns being called in the INNER Select statement. This will cause this error.


Resolve Issue
To Resolve this issue:

<%
Select (Select column2 from table 1 where column1=table2.column1)as MyColumn, Table2.Column1, Table2.Column2
%>


In the above statement, we removed the column of which the Query us being called, and only leaving the Column, in this case. Column2, to be utilized in our page.