Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with IN and NOT clauses

Author  Topic 

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2007-08-05 : 22:07:21
Hi,

I have a table that looks like this:

PRODUCTS
---------------
id | storeId | categoryId

I want to write a function that takes and "ProductID" and a "CategoryID" and returns results with just items that

1) Have that categoryId
2) Belong to the storeId that this "ProductID" is associate with
3) The "ProductID" product is NOT in the result set

I think I'd need to do something like this but I'm not sure


@categoryid int,
@itemid int

SELECT *
FROM
[item] A
WHERE
store_id=@storeid
and IN
(SELECT ..)
and NOT IN
(... @itemId)

Any help would be appreciated.




Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-08-06 : 13:32:11
I'm a little confused about your requirements. But, maybe this will work?
SELECT
*
FROM
Products
WHERE
StoreID = (SELECT StoreID FROM Products WHERE ProductID = @ProductID)
AND CategoryID = @CategoryID
AND ProductID <> @ProductID
Go to Top of Page
   

- Advertisement -