By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,574 Members | 1,977 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,574 IT Pros & Developers. It's quick & easy.

Help on Error:Only one expression can be specified in the select list when the subque

P: 4
Hi Everyone

I'm trying to create a stored procedure that will delete groups that are in-active for a month.

Table description i have two table which are linked together using groupID, when creating the group group info is stored into the group table including the date group was created, and when posting comment to the group, content is stored into the groupPost table.

I have the isDelete column on both table which is a bit data-type - for the group row to be de-actived i need to set is delete column to true.

where is my stored procedure:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.DeleteInActiveGroups
  2. AS
  3. UPDATE 
  4.         dbo.GroupPost
  5. SET 
  6.         dbo.GroupPost.isDeleted = 1
  7. WHERE
  8.         dbo.GroupPost.GroupID
  9. IN
  10. (
  11.         SELECT
  12.                 *
  13.         FROM
  14.                 dbo.Groups
  15.         WHERE
  16.                 dbo.Groups.DateCreated < DATEADD(MONTH, -1, GETDATE())
  17.         AND 
  18.                 Groups.UserID <> 37 OR Groups.UserID <> 36
  19. )
I keep on getting an error:Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Any help will be appreciated. Thanks in advance
Jan 29 '09 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 5,058

That doesn't look like MySQL code to me.
Which SQL server are you using?
Microsoft's SQL Server perhaps?

Let me know and I'll move this to the proper forum.
Jan 29 '09 #2

P: 4
Apologies, i didn't notice i'v posted to the wrong forum, it's SQL, I'm currently using SQL Server 2005, Enterprise Edition
Feb 4 '09 #3

Expert 2.5K+
P: 2,878
Change your subquery to:

Expand|Select|Wrap|Line Numbers
  1. SELECT GroupID
  2. FROM dbo.Groups
  3. WHERE
  4. dbo.Groups.DateCreated < DATEADD(MONTH, -1, GETDATE())
  5. AND 
  6. Groups.UserID <> 37 OR Groups.UserID <> 36
IN have some problems handling NULL. Read more about it here

Happy Coding!

-- CK
Feb 4 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.