Sunday, March 23, 2014

how to join two table and get best result?


SELECT GacFirstDetailAccountRef,
[1] AS title1,
GacSecondDetailAccountRef,
[2] AS title2,
GacThirdDetailAccountRef,
[3] AS title3,
credit,
debit
FROM
(
select vi.*,ar.DetailID,da.Title
from VoucherItem vi
CROSS APPLY (VALUES (GacFirstDetailAccountRef,1),(GacSecondDetailAccountRef,2),(GacThirdDetailAccountRef,3))ar(AcctRef,DetailID)
INNER JOIN DetailAccount da
ON da.Code = ar.AcctRef
)t
PIVOT (MAX(Title) FOR DetailID IN ([1],[2],[3]))p





Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://ift.tt/19nLNVq http://ift.tt/1iEAj0c


No comments:

Post a Comment