• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

SQL O/p Formatiing in sql server 2008R2

I have the following op.

                   Testname-Units                                       ADT - Value
BLOOD GLUCOSE (Fasting)(mg/dL)                               11/06/2014  05:49 - 115
BLOOD GLUCOSE (Fasting)(mg/dL)                               12/06/2014  06:06 - 120
BLOOD GLUCOSE (Fasting)(mg/dL)                                13/06/2014  06:40 - 163
BLOOD GLUCOSE (Fasting)(mg/dL)                                15/06/2014  06:52 - 93
BLOOD GLUCOSE (Fasting)(mg/dL)                                 16/06/2014  06:32 - 103

I want it to appear as below

Testname - Units                                                   ADT : Value
BLOOD GLUCOSE (Fasting)(mg/dL)                      11/06/2014  05:49 -115 |12/06/2014  06:06 - 120|                                            
                                                                                13/06/2014  06:40 -  163|15/06/2014  06:52 - 93| 16/06/2014  06:32 - 103 |

Like this for a given patient the  number of tests may vary and for given test, no of datetime can vary depending on the duration of patient stay in the hospital

After pre - defined | delimiter the column content should wrap to next line.

This is required for saving printing stationary   (Printout is taken in A4 size sheet)

I request an expert help in this regard at the earliest.

Thanks in advance
1 Solution
Russell FoxDatabase DeveloperCommented:
You can use the FOR XML construct in this post to concatenate multiple rows into a single string, although a better long-term solution may be to create an SSRS report to do this stuff for you. That will give you much better control over the formatting as printed.

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now