Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. FOR XML AUTO and column name with space problem in SQL Server 2005

FOR XML AUTO and column name with space problem in SQL Server 2005

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadminxml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    Here is my SQL select ID as [Emp ID], Name as [Employee name], Sal as [Salary] from Emp FOR XML AUTO, ELEMENTS, ROOT('customers') When I issue this SQL then unknown data is added in xml with my field name. I got the xml like <customers> <Emp> <Emp_x0020_ID>1</Emp_x0020_ID> <Employee_x0020_name>bob</Employee_x0020_name> <Salary>2020</Salary> </Emp> <Emp> <Emp_x0020_ID>2</Emp_x0020_ID> <Employee_x0020_name>keith</Employee_x0020_name> <Salary>6500</Salary> </Emp> <Emp> <Emp_x0020_ID>3</Emp_x0020_ID> <Employee_x0020_name>markc</Employee_x0020_name> <Salary>5400</Salary> </Emp> </customers> It shows <Emp_x0020_ID> instead of this <Emp ID> because I mention column alias with space like "Emp ID". how could modify my SQL as a result space will not be ignore I mean my xml would <customers> <Emp> <Emp ID>1</Emp ID> <Employee name>bob</Employee name> <Salary>2020</Salary> </Emp> </customers> please help me......urgent. look like

    tbhattacharjee

    L 1 Reply Last reply
    0
    • T Tridip Bhattacharjee

      Here is my SQL select ID as [Emp ID], Name as [Employee name], Sal as [Salary] from Emp FOR XML AUTO, ELEMENTS, ROOT('customers') When I issue this SQL then unknown data is added in xml with my field name. I got the xml like <customers> <Emp> <Emp_x0020_ID>1</Emp_x0020_ID> <Employee_x0020_name>bob</Employee_x0020_name> <Salary>2020</Salary> </Emp> <Emp> <Emp_x0020_ID>2</Emp_x0020_ID> <Employee_x0020_name>keith</Employee_x0020_name> <Salary>6500</Salary> </Emp> <Emp> <Emp_x0020_ID>3</Emp_x0020_ID> <Employee_x0020_name>markc</Employee_x0020_name> <Salary>5400</Salary> </Emp> </customers> It shows <Emp_x0020_ID> instead of this <Emp ID> because I mention column alias with space like "Emp ID". how could modify my SQL as a result space will not be ignore I mean my xml would <customers> <Emp> <Emp ID>1</Emp ID> <Employee name>bob</Employee name> <Salary>2020</Salary> </Emp> </customers> please help me......urgent. look like

      tbhattacharjee

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Tridip Bhattacharjee wrote:

      please help me......urgent.

      I don't see anything urgent here. However, if you read the XML specification you may notice that node names may not contain spaces, so your Emp ID label has been manipulated to make it comply with the rules.

      I must get a clever new signature for 2011.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups