This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » SQL and Databases » how to check if part is in a subquery
Reply

how to check if part is in a subquery

zachary anthony
Member



Since: 29 Jul 2010
Posts: 1
Posted 30 Jul 2010 00:11:55

If X is a subquery of components that need to be sent out for platting and @ITEM is a component and @ADJUSTMENT is a varriable I need to write something that does the following:

IF @ITEM IS IN X
SET @ADJUSTMENT = 7
ELSE
SET @ADJUSTMENT = 0

Help would be greately appreciated!

If you need to know, the subquery X returns nothing more or less than a list of items.

If X is a subquery of components that need to be sent out for platting and @ITEM is a component and @ADJUSTMENT is a varriable I need to write something that does the following:

IF @ITEM IS IN X
SET @ADJUSTMENT = 7
ELSE
SET @ADJUSTMENT = 0

Help would be greately appreciated!

If you need to know, the subquery X returns nothing more or less than a list of items.
Patrick Woldberg
Official Representative



Since: 11 Feb 2003
Posts: 1,894
Replied 05 Aug 2010 10:36:24
I'm not sure what you exactly want to retrieve, so here are some examples which I hope will help you.

couldn't you just do a select in the if statement like:

IF EXISTS(SELECT NULL FROM Table WHERE Item = @ITEM)


or if you need to use a subquery to check if the item is for example in a specific category which is in a other table:

SELECT NULL FROM Items WHERE Item = @ITEM AND ItemId IN (SELECT ItemId FROM ItemCategories WHERE Cat = @CAT)

Reply to this topic

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency