Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:22:19+00:00 2026-06-15T11:22:19+00:00

I am getting the following error in SQL Server: Msg 512, Level 16, State

  • 0

I am getting the following error in SQL Server:

Msg 512, Level 16, State 1, Line 18 Subquery returned more than 1
value. This is not permitted when the subquery follows =, !=, <, <= , > >, >= or when the subquery is used as an expression.

My code is as follows:

DECLARE
@personNumber varchar(20),
@itemNumber varchar(20)


SET @personNumber = 'null'
SET @itemNumber = 'null'

SELECT      
    OU.UserID
    ,OU.Name
    ,IGWQ.itemNumber
    ,IG.itemName
    ,IGWQ.QuantityOnHand
FROM dbo.Table1 IGWQ 
INNER JOIN Table2 OU        ON  IGWQ.UserId = OU.UserId
INNER JOIN Table3 IG        ON  IGWQ.itemNumber = IG.itemNumber
WHERE IGWQ.userid IN (CASE  WHEN @personNumber = 'null' 
                            THEN (  SELECT DISTINCT 
                                        UserID 
                                    FROM Table2 WITH(NOLOCK) 
                                    WHERE [Role] = '01')
                            ELSE @personNumber
                            END)
AND IGWQ.itemNumber IN (CASE    WHEN @itemNumber = 'null'
                                THEN (  SELECT DISTINCT 
                                            itemNumber 
                                        FROM dbo.Table1 WITH(NOLOCK))
                                ELSE @itemNumber
                                END)

Can anyone suggest a solution to this problem? I thought using ‘IN’ would have fixed the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:22:20+00:00Added an answer on June 15, 2026 at 11:22 am

    use this to fix the rest:

    WHERE ((@personNumber <> 'null' AND @personNumber = IGWQ.userid)
    OR (@personNumber = 'null' AND IGWQ.userid IN (  SELECT  UserID 
                                        FROM Table2 WITH(NOLOCK) 
                                        WHERE [Role] = '01')
       ))
    

    You don’t need the DISTINCT as the IN statement only handles distinct values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following error message with SQL Server 2005 Msg 120, Level
I'm getting the following error when trying to setup SQL Server 2005 DB Mirroring
Why am I getting a syntax error with the following line? statement = self.sql.execute(DESCRIBE
I am getting following error in my SQL server 2008 R2 database: Cannot use
I am getting the following error message from a bulk load in sql server
I am getting the following error when try to save. SQL Query: INSERT INTO
I tried using : sp_send_dbmail But I got the following error: Msg 15281, Level
I'm on SQL Server 2005 and I am getting an error which I am
I'm having trouble getting the following to work in SQL Server 2k, but it
I'm getting error while converting mysql insert statement into sql server 2008. because limit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.