How to output XML from a regular SQL query?

Write sql query to display following output:?

  • Employee name:smith designation:clerk salary:800 department:10 " " " " " all 14 employees details in same format

  • Answer:

    To display on multiple lines like that, you'd need an external report formatter like Crystal Reports. Native SQL is designed to output in tablular form with one line per row.

Shilpa at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

select [employee name], designation, salary, department from employee_table

The output asked for incorporates the Line Feed or Carriage Return for showing the details. In MS SQL we can represent the Line Feed by using either Char(13) or Char(10). Here we will have to use the "Results to Text" [Ctrl+T] feature of MS SQL to see the difference in the output. The query to get the desired output would somewhat look like: select 'Employee name:' emp.empname + Char(13) / Char(10) + 'designation:' emp.desig + Char(13) / Char(10) + 'salary:' emp.sal + Char(13) / Char(10) + 'department:' emp.dept + Char(13) / Char(10) + " " " from employee emp same for all 14 employees details.

We need more info e.g Table name Cnt do query with just this info

TheMadProfessor is wrong on this, you can output this way without a reporting tool. If results are being set in a grid in your sql app, then set the output to text. The code below is t-sql -- declare variables declare @newline varchar(2) -- Set variables -- Carriage return is 13 and Line feed is 10, -- this will cause a new line on the standard output set @newline = CHAR(13) + CHAR(10) -- Select the data with labels and newlines in a single string SELECT 'Employee name:' + convert(varchar, [employee]) + @newline + 'designation:' + convert(varchar, [designation]) + @newline + 'salary:' + convert(varchar, [salary]) + @newline + 'department:' + convert(varchar, [department]) + @newline FROM [dbo].[employee] GO

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.