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 8118541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:31:18+00:00 2026-06-06T04:31:18+00:00

I created a SQL query which receives different parameters. When I pass a parameter

  • 0

I created a SQL query which receives different parameters. When I pass a parameter just to Region-ID I got an error:

System.Data.SqlClient.SqlException: Ambiguous column name ‘REGION_ID’

When I pass data to other parameters its working without a problem.

I build a string for the sql query:

StringBuilder constrains = new StringBuilder();
AppendConstrain(constrains, "RAUMKLASSE_ID", RAUMKLASSE_ID);
AppendConstrain(constrains, "STADT_ID", STADT_ID);
AppendConstrain(constrains, "GEBAEUDE_ID", GEBAEUDE_ID);
AppendConstrain(constrains, "REGION_ID", REGION_ID);
AppendConstrain(constrains, "RAUMATTRIBUTE_ID", RAUMATTRIBUTE_ID);
AppendConstrain2(constrains, "r.REGION_ID", "reg.ID");
AppendConstrain2(constrains, "r.STADT_ID", "st.ID");
AppendConstrain2(constrains, "r.ETAGE_ID", "et.ID");

and here is my SQL query:

StringBuilder query =
            new StringBuilder("SELECT DISTINCT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID,reg.NAME AS REGNAME, st.NAME AS STNAME, et.BEZEICHNUNG as ETBEZEICHNUNG FROM RAZUORDNUNG rz right join RAUMATTRIBUTE ra ON rz.RAUMATTRIBUTE_ID = ra.ID right join RAUM r ON rz.RAUM_ID = r.ID, REGION reg, STADT st, ETAGE et");

I don’t know where the problem is?

EDIT:

here is the append string function:

private static void AppendConstrain(StringBuilder query, string name, string value)
    {
        if (String.IsNullOrEmpty(value))
            return;

        if (query.Length > 0)
            query.Append(" AND ");

        query.AppendFormat("{0} IN ({1})", name, value);
    }

    private static void AppendConstrain2(StringBuilder query, string name, string name2)
    {
        if (String.IsNullOrEmpty(name2))
            return;

        if (query.Length > 0)
            query.Append(" AND ");

        query.AppendFormat("{0} = ({1})", name, name2);
    }
  • 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-06T04:31:19+00:00Added an answer on June 6, 2026 at 4:31 am

    You appear to be appending the constraint twice for REGION_ID.

    Qualify this line with the table:

    AppendConstrain(constrains, "REGION_ID", REGION_ID);
    

    becomes

    AppendConstrain(constrains, "<table/alias>.REGION_ID", REGION_ID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me to find out error in my SQL query. I have created
I have a parameterized SQL query targetted for SQL2005 which is dynamically created in
I have created a data frame from a SQL query using the RODBC package.
I've got an ORACLE package which receives few parameters and returns - with some
I have a SQL Server query which runs just fine -- until I add
I'm using MS SQL 2005 and I have created a CTE query to return
I am trying to bind to the results of a Linq-To-SQL query, which I
I've just received a new data source for my application which inserts data into
I am trying to execute a sql query which will create a new table
Strange performance outcome, I have a LINQ to SQL query which uses several let

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.