Я работаю с этими двумя таблицами, cl_line_rem
& Remark_code
.Они объединяются в столбце Remark_code_id
.
select Claim_id, Linenum, Remark_code_ID
from claim_line_remark
where claim_id = 13639035
Вывод:
Claim_id Linenum Remark_code_ID
---------------------------------------
13639035 1 697
13639035 1 739
13639035 1 1322
13639035 2 697
13639035 2 739
13639035 2 1322
13639035 3 697
13639035 3 739
13639035 3 1322
13639035 4 697
13639035 4 739
13639035 4 1322
13639035 5 697
13639035 5 739
13639035 5 1322
13639035 6 697
13639035 6 739
13639035 6 1322
select clr.claim_id, clr.linenum, clr.remark_code_id, rc.name
from claim_line_remark clr
inner join Remark_Code rc on clr.Remark_Code_ID = rc.Remark_Code_ID
where claim_id = 13639035
Вывод:
claim_id linenum Remark_code_id Name
------------------------------------------------
13639035 1 697 HAWAII FFS SCHEDULE
13639035 1 739 DO NOT BALANCE BILL.
13639035 1 1322 SUPPRESS ALL EOB
13639035 2 697 HAWAII FFS SCHEDULE
13639035 2 739 DO NOT BALANCE BILL.
13639035 2 1322 SUPPRESS ALL EOB
13639035 3 697 HAWAII FFS SCHEDULE
13639035 3 739 DO NOT BALANCE BILL.
13639035 3 1322 SUPPRESS ALL EOB
13639035 4 697 HAWAII FFS SCHEDULE
13639035 4 739 DO NOT BALANCE BILL.
13639035 4 1322 SUPPRESS ALL EOB
13639035 5 697 HAWAII FFS SCHEDULE
13639035 5 739 DO NOT BALANCE BILL.
13639035 5 1322 SUPPRESS ALL EOB
13639035 6 697 HAWAII FFS SCHEDULE
13639035 6 739 DO NOT BALANCE BILL.
13639035 6 1322 SUPPRESS ALL EOB
Я пытался использовать этот код с Stuffфункция, но, кажется, не работает точно:
select
clr.Claim_ID, clr.Linenum,
stuff((select '; ' + rc.Name
from Remark_Code rc
where rc.Remark_Code_ID = clr.Remark_Code_ID
for xml path('')), 1, 1, '') [Remarks]
from
Claim_Line_Remark clr
where
claim_id in (13639035)
Что я ищу, это,
Claim_id Linenum Name
------------------------------------------------------------------------------
13639035 1 HAWAII FFS SCHEDULE,DO NOT BALANCE BILL,SUPPRESS ALL..
13639035 2 HAWAII FFS SCHEDULE,DO NOT BALANCE BILL,SUPPRESS ALL..
13639035 3 HAWAII FFS SCHEDULE,DO NOT BALANCE BILL,SUPPRESS ALL..
13639035 4 HAWAII FFS SCHEDULE,DO NOT BALANCE BILL,SUPPRESS ALL..
13639035 5 HAWAII FFS SCHEDULE,DO NOT BALANCE BILL,SUPPRESS ALL..
13639035 6 HAWAII FFS SCHEDULE,DO NOT BALANCE BILL,SUPPRESS ALL..
Что я получаю с текущим кодом, это,
13639035 1 HAWAII FFS SCHEDULE
13639035 1 DO NOT BALANCE BILL.
13639035 1 SUPPRESS ALL EOB
13639035 2 HAWAII FFS SCHEDULE
13639035 2 DO NOT BALANCE BILL.
13639035 2 SUPPRESS ALL EOB
13639035 3 HAWAII FFS SCHEDULE
13639035 3 DO NOT BALANCE BILL.
13639035 3 SUPPRESS ALL EOB
13639035 4 HAWAII FFS SCHEDULE
13639035 4 DO NOT BALANCE BILL.
13639035 4 SUPPRESS ALL EOB
13639035 5 HAWAII FFS SCHEDULE
13639035 5 DO NOT BALANCE BILL.
13639035 5 SUPPRESS ALL EOB
13639035 6 HAWAII FFS SCHEDULE
13639035 6 DO NOT BALANCE BILL.
13639035 6 SUPPRESS ALL EOB