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
 General SQL Server Forums
 New to SQL Server Programming
 Case in the From clause!

Author  Topic 

moodi_z
Starting Member

38 Posts

Posted - 2009-08-30 : 04:23:50
Hi,
How can I perform such a select statement:


SELECT BarcodeID,
CatalogID,
[Description]

FROM Tbl_StockTackingData INNER JOIN
CASE Left(BarcodeID,2)
WHEN 'RM' THEN Tbl_RawMaterial ON Tbl_StockTackingData.BarcodeID = Tbl_RawMaterial.BarcodeUID
WHEN 'RL' THEN Tbl_Rolls ON Tbl_StockTackingData.BarcodeID = Tbl_Rolls.BarcodeUID
WHEN 'PL' THEN Tbl_BagsPallet ON Tbl_StockTackingData.BarcodeID = Tbl_BagsPallet.BarcodeUID
END


Thanks in advance.

moodi_z
Starting Member

38 Posts

Posted - 2009-08-30 : 04:36:44
I did something like that:

SELECT BarcodeID,
--CatalogID,
CASE Left(BarcodeID,2)
WHEN 'RM' THEN Tbl_RawMaterial.CatalogID
WHEN 'RL' THEN Tbl_Rolls.CatalogID
WHEN 'PL' THEN Tbl_BagsPallet.CatalogID
END AS CatalogID
--[Description]

FROM Tbl_StockTackingData LEFT JOIN
Tbl_RawMaterial ON Tbl_StockTackingData.BarcodeID = Tbl_RawMaterial.BarcodeUID left JOIN
Tbl_Rolls ON Tbl_StockTackingData.BarcodeID = Tbl_Rolls.BarcodeUID left JOIN
Tbl_BagsPallet ON Tbl_StockTackingData.BarcodeID = Tbl_BagsPallet.BarcodeUID

is it the right thing to do or there are more official ways?
Go to Top of Page
   

- Advertisement -