Results will be spliced into a string sqlserver
The above mentioned id the SELECT 1, name from table1 for xml path 2 --id and name for the real field of table1
- no argument following path, each row of data is the default <row> tag package, each row of data which is to be wrapped column name tag.
Sql above result may be as follows:
1 <row> 2 <id>1</id> 3 <name>holab</name> 4 </row> 5 <row> 6 <id>2</id> 7 <name>name1</name> 8 </row> 9 ....
- each row of the outermost wrap label parameter controlled by the path (without parameters, defaults Row), thus can be removed directly to a path of the empty string as a parameter.
1 select (select id+'',name+'' from table1 for xml path(''))
result:
1 1holab2name1....
#stuff function
#row_number () over (order by column) - Add the number row for the query results
1 select id,name,row_number over(order by id) as num from table1
result:
1 id name num 2 1 holab 1 3 2 name1 2 4 4 name 3 5 ....
# Query results spliced into comma delimited string - Each data separated by a comma
1 select stuff((select ','+id+':',name+'' from table1 for xml path('')),1,1,'')
result:
1 1:holab,2:name1....
# The results of each data line feed display (the beginning of each line to add number)
1 select (select row_number() over(order by id)+'、',id+':',name+char(10) from table1 for xml path(''))
result:
1,1. 1: holab 2 2,2 &: NAME2 . 3 .... . 4. 5 --char (10) is in line feed sql server 6 - as the last line has line break, the final row will be more blank lines
The above mentioned id the SELECT 1, name from table1 for xml path 2 --id and name for the real field of table1
- no argument following path, each row of data is the default <row> tag package, each row of data which is to be wrapped column name tag.
Sql above result may be as follows:
1 <row> 2 <id>1</id> 3 <name>holab</name> 4 </row> 5 <row> 6 <id>2</id> 7 <name>name1</name> 8 </row> 9 ....
- each row of the outermost wrap label parameter controlled by the path (without parameters, defaults Row), thus can be removed directly to a path of the empty string as a parameter.
1 select (select id+'',name+'' from table1 for xml path(''))
result:
1 1holab2name1....
#stuff function
#row_number () over (order by column) - Add the number row for the query results
1 select id,name,row_number over(order by id) as num from table1
result:
1 id name num 2 1 holab 1 3 2 name1 2 4 4 name 3 5 ....
# Query results spliced into comma delimited string - Each data separated by a comma
1 select stuff((select ','+id+':',name+'' from table1 for xml path('')),1,1,'')
result:
1 1:holab,2:name1....
# The results of each data line feed display (the beginning of each line to add number)
1 select (select row_number() over(order by id)+'、',id+':',name+char(10) from table1 for xml path(''))
result:
1,1. 1: holab 2 2,2 &: NAME2 . 3 .... . 4. 5 --char (10) is in line feed sql server 6 - as the last line has line break, the final row will be more blank lines