Live Scores
Shareware
Movie Stars
in
Visual Interdev
Applications
(Entire Site)
Questions and answers to issues related to Microsoft: Windows, Applications, Development, Hardware, Server, Internet Protocols, Database, Exchange .
»
Applications
»
Visual Interdev
»
SQL String Concat with XML PATH() function. MS SQL SERVER 2005
SQL String Concat with XML PATH() function. MS SQL SERVER 2005
Table: LS_Notes
acctno patno seqno textdata
11 1 1 8/29/05 KL WANTS
11 1 2 SUIZ SHE WILL SCHEDULE/
11 1 3 9/15/05 SENT PREP
11 1 5 10/13/05 SENT COPY
22 1 1 1/3/06 CIGNA POS ID
22 1 2 800-244-6224 CLAIMS PO
22 1 3 SENT PREP INSTRUCTIONS
The ultimate goal here - is to concatenate all of that particular person's notes based on acct_no, and dump the data into a new table where we can see all the data as one sentence, and have only one record per person. The seqno field above is the order in which they must be concatenated, and we need the sequence in reverse order (highest seqno to lowest seq no.
End Result:
Table Name: New_Table
acctno Comment_Text
11 10/13/05 SENT COPY, 9/15/05 SENT PREP, SUIZ SHE WILL SCHEDULE/, 8/29/05 KL WANTS
22 SENT PREP INSTRUCTIONS, 800-244-6224 CLAIMS PO, 1/3/06 CIGNA POS ID
the code that works so far is:
SELECT p1.src_patient_id,
( SELECT textdata + ','
FROM LS_Notes p2
WHERE p2.src_patient_id = p1.src_patient_id
ORDER BY textdata
FOR XML PATH('') ) AS textdata
FROM LS_Notes p1
GROUP BY src_patient_id;
However, this doesnt take into account the seq no above. Can someone please show me how to alter this code to allow for correct reverse numerical sequencing?
Thanks in advance!
Solution: SQL String Concat with XML PATH() function. MS SQL SERVER 2005
Try changing your
order by textdata
to
order by seqno desc