Monday, November 25, 2013

IF condition JOIN this or this

s there a way to do something like this in t-sql?



For example, I have a table storing summary data for ordered items and stock items. For ordered items, both the OrderID field and the ItemId field will have numbers. For stock items, OrderID field will be NULL. Here is what need to be done:



IF [OrderId] IS NULL THEN JOIN this StockItems table ELSE JOIN that OrderItems table



I want it to return one recordset containing both type of items in one stored procedure for further processing. Is this possible?


--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in Sets / Trees and Hierarchies in SQL


No comments:

Post a Comment