Getting error “Only one expression can be specified in the select list…”
up vote
0
down vote
favorite
I am trying to add a column to a view with the following code:
SELECT ';' + CONTEXT as DriverNotes,
(STUFF((SELECT CustomerID FROM Notes E2 WHERE E2.CustomerID IN (Notes.CustomerID)
FOR XML PATH(''), TYPE, ROOT).value('root[1]','nvarchar(5)'),1,0,'')) as CustomerID FROM NOTES
On it's own it works just fine. When I run it within a View however, I get the following error:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
I realize that the code here is trying to call two columns and that is what is giving me the error, but I only want one, and that would be CONTEXT. I need this to correlate with Notes.CustomerID but without the column appearing in the query.
I am still quite new to this, so any help would be greatly appreciated.
sql sql-server select
add a comment |
up vote
0
down vote
favorite
I am trying to add a column to a view with the following code:
SELECT ';' + CONTEXT as DriverNotes,
(STUFF((SELECT CustomerID FROM Notes E2 WHERE E2.CustomerID IN (Notes.CustomerID)
FOR XML PATH(''), TYPE, ROOT).value('root[1]','nvarchar(5)'),1,0,'')) as CustomerID FROM NOTES
On it's own it works just fine. When I run it within a View however, I get the following error:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
I realize that the code here is trying to call two columns and that is what is giving me the error, but I only want one, and that would be CONTEXT. I need this to correlate with Notes.CustomerID but without the column appearing in the query.
I am still quite new to this, so any help would be greatly appreciated.
sql sql-server select
What do you mean when you "run it in a view"? What is the definition of your View?
– Larnu
yesterday
Sorry I am probably using the wrong terminology, but I have dropped and created a view with the intention of adding the code I posted above. When I go to execute the query, I get the error mentioned above.
– Moodsy
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to add a column to a view with the following code:
SELECT ';' + CONTEXT as DriverNotes,
(STUFF((SELECT CustomerID FROM Notes E2 WHERE E2.CustomerID IN (Notes.CustomerID)
FOR XML PATH(''), TYPE, ROOT).value('root[1]','nvarchar(5)'),1,0,'')) as CustomerID FROM NOTES
On it's own it works just fine. When I run it within a View however, I get the following error:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
I realize that the code here is trying to call two columns and that is what is giving me the error, but I only want one, and that would be CONTEXT. I need this to correlate with Notes.CustomerID but without the column appearing in the query.
I am still quite new to this, so any help would be greatly appreciated.
sql sql-server select
I am trying to add a column to a view with the following code:
SELECT ';' + CONTEXT as DriverNotes,
(STUFF((SELECT CustomerID FROM Notes E2 WHERE E2.CustomerID IN (Notes.CustomerID)
FOR XML PATH(''), TYPE, ROOT).value('root[1]','nvarchar(5)'),1,0,'')) as CustomerID FROM NOTES
On it's own it works just fine. When I run it within a View however, I get the following error:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
I realize that the code here is trying to call two columns and that is what is giving me the error, but I only want one, and that would be CONTEXT. I need this to correlate with Notes.CustomerID but without the column appearing in the query.
I am still quite new to this, so any help would be greatly appreciated.
sql sql-server select
sql sql-server select
edited yesterday
asked yesterday
Moodsy
11
11
What do you mean when you "run it in a view"? What is the definition of your View?
– Larnu
yesterday
Sorry I am probably using the wrong terminology, but I have dropped and created a view with the intention of adding the code I posted above. When I go to execute the query, I get the error mentioned above.
– Moodsy
yesterday
add a comment |
What do you mean when you "run it in a view"? What is the definition of your View?
– Larnu
yesterday
Sorry I am probably using the wrong terminology, but I have dropped and created a view with the intention of adding the code I posted above. When I go to execute the query, I get the error mentioned above.
– Moodsy
yesterday
What do you mean when you "run it in a view"? What is the definition of your View?
– Larnu
yesterday
What do you mean when you "run it in a view"? What is the definition of your View?
– Larnu
yesterday
Sorry I am probably using the wrong terminology, but I have dropped and created a view with the intention of adding the code I posted above. When I go to execute the query, I get the error mentioned above.
– Moodsy
yesterday
Sorry I am probably using the wrong terminology, but I have dropped and created a view with the intention of adding the code I posted above. When I go to execute the query, I get the error mentioned above.
– Moodsy
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Check this query. I think this is what you want :
SELECT Notes.CustomerId,
STUFF(
(SELECT ';' + CONTEXT FROM Notes E2
WHERE E2.CustomerId = Notes.CustomerId
FOR XML PATH ('')), 1, 1, ''
) DriverNotes
FROM Notes /*Probably it should be Customer table */
GROUP BY Notes.CustomerId
This works similar to the code I posted. It does not work when creating a View though. Thank you for the reply.
– Moodsy
yesterday
okay. could you add your expected output to your post .
– Zeki Gumus
yesterday
I did, I also added the View I am trying to edit. The expected output would be to just add a single column "Context" to [dbo].[VCustomerJoinLocations].
– Moodsy
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Check this query. I think this is what you want :
SELECT Notes.CustomerId,
STUFF(
(SELECT ';' + CONTEXT FROM Notes E2
WHERE E2.CustomerId = Notes.CustomerId
FOR XML PATH ('')), 1, 1, ''
) DriverNotes
FROM Notes /*Probably it should be Customer table */
GROUP BY Notes.CustomerId
This works similar to the code I posted. It does not work when creating a View though. Thank you for the reply.
– Moodsy
yesterday
okay. could you add your expected output to your post .
– Zeki Gumus
yesterday
I did, I also added the View I am trying to edit. The expected output would be to just add a single column "Context" to [dbo].[VCustomerJoinLocations].
– Moodsy
yesterday
add a comment |
up vote
0
down vote
Check this query. I think this is what you want :
SELECT Notes.CustomerId,
STUFF(
(SELECT ';' + CONTEXT FROM Notes E2
WHERE E2.CustomerId = Notes.CustomerId
FOR XML PATH ('')), 1, 1, ''
) DriverNotes
FROM Notes /*Probably it should be Customer table */
GROUP BY Notes.CustomerId
This works similar to the code I posted. It does not work when creating a View though. Thank you for the reply.
– Moodsy
yesterday
okay. could you add your expected output to your post .
– Zeki Gumus
yesterday
I did, I also added the View I am trying to edit. The expected output would be to just add a single column "Context" to [dbo].[VCustomerJoinLocations].
– Moodsy
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
Check this query. I think this is what you want :
SELECT Notes.CustomerId,
STUFF(
(SELECT ';' + CONTEXT FROM Notes E2
WHERE E2.CustomerId = Notes.CustomerId
FOR XML PATH ('')), 1, 1, ''
) DriverNotes
FROM Notes /*Probably it should be Customer table */
GROUP BY Notes.CustomerId
Check this query. I think this is what you want :
SELECT Notes.CustomerId,
STUFF(
(SELECT ';' + CONTEXT FROM Notes E2
WHERE E2.CustomerId = Notes.CustomerId
FOR XML PATH ('')), 1, 1, ''
) DriverNotes
FROM Notes /*Probably it should be Customer table */
GROUP BY Notes.CustomerId
answered yesterday
Zeki Gumus
2816
2816
This works similar to the code I posted. It does not work when creating a View though. Thank you for the reply.
– Moodsy
yesterday
okay. could you add your expected output to your post .
– Zeki Gumus
yesterday
I did, I also added the View I am trying to edit. The expected output would be to just add a single column "Context" to [dbo].[VCustomerJoinLocations].
– Moodsy
yesterday
add a comment |
This works similar to the code I posted. It does not work when creating a View though. Thank you for the reply.
– Moodsy
yesterday
okay. could you add your expected output to your post .
– Zeki Gumus
yesterday
I did, I also added the View I am trying to edit. The expected output would be to just add a single column "Context" to [dbo].[VCustomerJoinLocations].
– Moodsy
yesterday
This works similar to the code I posted. It does not work when creating a View though. Thank you for the reply.
– Moodsy
yesterday
This works similar to the code I posted. It does not work when creating a View though. Thank you for the reply.
– Moodsy
yesterday
okay. could you add your expected output to your post .
– Zeki Gumus
yesterday
okay. could you add your expected output to your post .
– Zeki Gumus
yesterday
I did, I also added the View I am trying to edit. The expected output would be to just add a single column "Context" to [dbo].[VCustomerJoinLocations].
– Moodsy
yesterday
I did, I also added the View I am trying to edit. The expected output would be to just add a single column "Context" to [dbo].[VCustomerJoinLocations].
– Moodsy
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417130%2fgetting-error-only-one-expression-can-be-specified-in-the-select-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean when you "run it in a view"? What is the definition of your View?
– Larnu
yesterday
Sorry I am probably using the wrong terminology, but I have dropped and created a view with the intention of adding the code I posted above. When I go to execute the query, I get the error mentioned above.
– Moodsy
yesterday