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

  • Home
  • SEARCH
  • 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 285795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:34:43+00:00 2026-05-12T05:34:43+00:00

This is my query as it is now. I want to add another column

  • 0

This is my query as it is now. I want to add another column to the result checking if the ItemID is equal to any value in another table column (BuildComponents.ComponentID). Eg. writing ‘Y’ if its there and ‘N’ if its not. I do not want this to affect what rows are returned. I am using MS SQL 2005. The logic would be something like this:

if(ItemID is in (select ComponentID from BuildComponents)
return ‘Y’
else
return ‘N’

SELECT
'Item' AS type,
i.ItemID,
i.ItemNumber AS prodid,
i.ItemName AS 'desc',
i.SellUnitMeasure AS unit,
i.SellUnitQuantity AS quantity,
i.VATExclusiveStandardCost AS pricein,
i.BaseSellingPrice AS priceout,
v1.VATPercentageRate AS vatRateIn,
1 AS vatTypeIn,
v1.VATCode AS VATCodeIn,
v1.VATCodeDescription AS VATCodeDescriptionIn,
v2.VATPercentageRate AS vatRateOut,
2 AS vatTypeOut,
v2.VATCode AS VATCodeOut,
v2.VATCodeDescription AS VATCodeDescriptionOut,
i.IsInactive AS inactive,
s.CardRecordID AS VendID,
i.SupplierItemNumber AS VendCode,
i.VATExclusiveStandardCost AS VendInPrice,
i.ItemDescription AS ProductNote,
i.CustomField1,
i.CustomField2,
i.CustomField3,
cl1.CustomListText AS CustomField4,
cl1.CustomListName AS CustomField4Name,
cl2.CustomListText AS CustomField5,
cl2.CustomListName AS CustomField5Name,
cl3.CustomListText AS CustomField6,
cl3.CustomListName AS CustomField6Name,
'' AS QuantityOnHand,
'' AS LocationName,
i.PriceIsInclusive,
i.ItemIsStocked,
ISNULL(l1.LocationName, ISNULL(l2.LocationName, 'Default Warehouse')) AS DefaultLocation,
i.PositiveAverageCost as cost
FROM Items i
LEFT JOIN ItemLocations il ON il.ItemID = i.ItemID AND il.ItemID IS NULL
LEFT JOIN VATCodes v2 ON v2.VATCodeID = i.SellVATCodeID
LEFT JOIN VATCodes v1 ON v1.VATCodeID = i.BuyVATCodeID
LEFT JOIN Suppliers s ON s.SupplierID = i.PrimarySupplierID
LEFT JOIN CustomLists cl1 ON cl1.CustomListID = i.CustomList1ID
LEFT JOIN CustomLists cl2 ON cl2.CustomListID = i.CustomList2ID
LEFT JOIN CustomLists cl3 ON cl3.CustomListID = i.CustomList3ID
LEFT JOIN Locations l1 ON l1.LocationID = i.DefaultSellLocationID
LEFT JOIN Locations l2 ON l2.LocationID = 1
  • 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-05-12T05:34:43+00:00Added an answer on May 12, 2026 at 5:34 am

    The way to do this is to left join to the target table, and if the column is null then it is ‘N’, else ‘Y’ with a case statement.

    However, if ComponentID is not unique in BuildComponents you may get more results than you expected, so you need a distinct subquery to stop that from happening.

    To your join list add

    LEFT JOIN (SELECT DISTINCT ComponentID FROM BuildComponents) BC ON BC.ComponentID = i.ItemID
    

    To your select fields, you need to add another column,

    CASE WHEN BC.ComponentID IS NULL THEN 'N' ELSE 'Y' END as MyColName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query now that shows me all the calls between this time,
Right now I have this SQL query which is valid but always times out:
I have the following query, now the strange thing is if I run this
This query that I have is returning therapists whose 'therapistTable.activated' is equal to false
This query fails when I add the line shown... Select Companyid, count(*) as cnt
I don't know how to query this one out. I have a table structure
I want to add a relationship between multiple existing entities and another existing entity.
I want edit out put of django runserver ... i want add now object
now i use this code: $welcome_text = mysql_query(SELECT * FROM `text` WHERE `name` =
This query gives me syntax error in when-between line. how can i solve them?

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.