views:

46

answers:

1

i pass parameter as productid, i check in productrelated table whether this product related product are there or not if it is not there i want to check sample productid in departmentreplated table if it is not there i find the department of the productid and find the that productid related department product..

Plz help me how to write the store procedure.... which logic i want to use....

help me writing procedure.... reply as soon as ... thanks...

+1  A: 

I guess you really want an answer on this and tried your best to formulate the question.

The way you describe it you need to do that with a SELECT statement that does a LEFT JOIN. I cannot help you with the store procedure on SQL-SERVER but I guess you can figure out the rest once you have the SELECT.

SELECT ISNULL(p.someValue, d.someValue)
FROM DepartmentRelatedTable d
LEFT JOIN ProductRelatedTable p on (d.ProductId = p.ProductId)
WHERE d.ProductId = <some id here>

You maybe need to do a FULL JOIN instead of a LEFT JOIN because. I could not fully understand the data model you are using.

Jürgen Hollfelder