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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:21:27+00:00 2026-06-03T22:21:27+00:00

How can I change following query, so that I’m able to parameterize the SparePartNames

  • 0

How can I change following query, so that I’m able to parameterize the SparePartNames?

It returns all ID’s of repairs where not all mandatory spareparts were changed, in other words where at least one part is missing.

Note that the number of spareparts might change in future not only the names. Is it possible without using a stored procedure with dynamic SQL? If not, how could this SP look like?

Edit: Note that i do not need to know how to pass a list/array as parameter, this is asked myriads of time on SO. I’ve also already a Split table-valued-function. I’m just wondering how i could rewrite the query to be able to join(or whatever) with a list of mandatory parts, so that i’ll find all records where at least one part is missing. So is it possible to use a varchar-parameter like '1264-3212,1254-2975' instead of a list of NOT EXISTS? Sorry for the confusion if it was not clear in the first place.

SELECT  d.idData
FROM    tabData d
INNER JOIN modModel AS m ON d.fiModel = m.idModel 
WHERE  (m.ModelName = 'MT27I') 
AND (d.fiMaxServiceLevel >= 2) 
AND (d.Manufacture_Date < '20120511') 
AND (NOT EXISTS
      (SELECT NULL
        FROM  tabDataDetail AS td 
        INNER JOIN tabSparePart AS sp ON sp.idSparePart = td.fiSparePart
        WHERE (td.fiData = d.idData) 
        AND (sp.SparePartName = '1264-3212'))
    OR (NOT EXISTS
      (SELECT NULL
        FROM  tabDataDetail AS td 
        INNER JOIN tabSparePart AS sp ON sp.idSparePart = td.fiSparePart
        WHERE (td.fiData = d.idData) 
        AND (sp.SparePartName = '1254-2975'))
    )
)

Unfortunately I don’t see how I could use sp.SparePartName IN/NOT IN(@sparePartNames) here.

  • 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-03T22:21:30+00:00Added an answer on June 3, 2026 at 10:21 pm

    Assuming there is (or will be) a table or view of mandatory spare parts, a list of exists can be replaced with a left join to tabDataDetail / tabSparePart pair on SparePartName; non-matches are reported back using td.fiSparePart is null.

    ; with mandatorySpareParts (SparePartName) as (
      select '1264-3212'
      union all
      select '1254-2975'
    )
    SELECT  d.idData
    FROM    tabData d
    INNER JOIN modModel AS m ON d.fiModel = m.idModel 
    WHERE  (m.ModelName = 'MT27I') 
    AND (d.fiMaxServiceLevel >= 2) 
    AND (d.Manufacture_Date < '20120511') 
    AND exists
    (
      SELECT null
        from mandatorySpareParts msp
        left join ( tabDataDetail AS td 
                    INNER JOIN tabSparePart AS sp 
                       ON sp.idSparePart = td.fiSparePart 
                      AND td.fiData = d.idData
                  )
          ON msp.SparePartName = sp.SparePartName
       WHERE td.fiSparePart is null
    )
    

    Part names should be replaced by their id’s, which would simplify left join and speed the query up.

    EDIT: i’ve errorneously left filtering of td in where clause, which invalidated left join. It is now in ON clause where it belongs.

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

Sidebar

Related Questions

I have the following Sql Query that returns the type of results that I
Can someone help me understand why the following query is not offsetting correctly? It's
I have the following html structure (which is generated and I can't change): <table
Does anyone know how I can achieve the following effect in OpenGL: Change the
Can someone tell me how i can change the .xml file that a flash
I have the following LINQ query that I need to translate to Entity SQL
I have the following query: ALTER TABLE table CHANGE field1 field1 INTEGER Is there
I'm trying to pass an object like that <% if( can? :change, comment.karma, comment.user_id)%>
I'm using a SQL query that is similar to the following form: SELECT col1,
I have the following query that (in my opinion) is far too long than

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.