1

I want to display column called SampleDate from table SampleTable where column SampleAgencyName = something and below the date I want to display the value of a column called SampleNumber.

I mean the results should be something like this.

 <tr>
    <td> 
    Date1
    SampleNumber1
    </td>
    <td> 
    Date2
    SampleNumber2
    </td>
    </tr>

I want to do this using FOR XML Path Root in SQL SERVER.

I can get just the dates to work easily.

SELECT SampleDate 'td' from SampleTable T where SampleAgencyName = 'something' for xml path('tr'), root('table')

My issue how to get the value for the SampleNumber column under the date.

2
  • Which language are you using? Commented Nov 10, 2011 at 16:14
  • @RedFilter ...I have posted what I have tried! Commented Nov 10, 2011 at 16:21

1 Answer 1

1

Try this

SELECT SampleDate + '    ' + SampleNumber 'td' from SampleTable T where SampleAgencyName = 'something' for xml path('tr'), root('table')

Cast the colums as varchar in case any of them is numeric

In place of space you can use char(13) this will give the results in next line

SELECT SampleDate + char(13)
 + SampleNumber 'td' from SampleTable T where SampleAgencyName = 'something' for xml path('tr'), root('table')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.