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



thanks dear


i edit your code



SELECT GacFirstDetailAccountRef,
[1] AS title1,
GacSecondDetailAccountRef
,
[2] AS title2,
GacThirdDetailAccountRef
,
[3] AS title3,
GacFourthDetailAccountRef
,
[4] as title4,
GacFifthDetailAccountRef
,
[5] as title5,
GacSixthDetailAccountRef
,
[6] as title6,
credit
,
debit
FROM
(
select vi.*,ar.DetailID,da.DurationType

from VoucherItem vi
CROSS APPLY (VALUES (GacFirstDetailAccountRef,1),(GacSecondDetailAccountRef,2),(GacThirdDetailAccountRef,3),(GacFourthDetailAccountRef,4),(GacFifthDetailAccountRef,5),(GacSixthDetailAccountRef,6))ar(AcctRef,DetailID)
INNER JOIN DetailAccount da
ON da.Code = ar.AcctRef
)t
PIVOT
(MAX3\
(Title) FOR DetailID IN ([1],[2],[3],[4],[5],[6]))p



but i see this error


Msg 102, Level 15, State 1, Line 24

Incorrect syntax near '\'.


how to solve it


pls help me




Name of Allah, Most Gracious, Most Merciful and He created the human


No comments:

Post a Comment