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.
| 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 | categoryIdI want to write a function that takes and "ProductID" and a "CategoryID" and returns results with just items that 1) Have that categoryId2) Belong to the storeId that this "ProductID" is associate with3) The "ProductID" product is NOT in the result setI think I'd need to do something like this but I'm not sure@categoryid int,@itemid int SELECT * FROM [item] AWHERE 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 ProductsWHERE StoreID = (SELECT StoreID FROM Products WHERE ProductID = @ProductID) AND CategoryID = @CategoryID AND ProductID <> @ProductID |
 |
|
|
|
|
|