Добро пожаловать в форум, Guest >> Войти | Регистрация | Поиск | Правила | | В избранное | Подписаться | ||
Все форумы / Microsoft SQL Server |
![]() ![]() |
marvel Member Откуда: Сообщений: 1066 |
declare @t table (id int,idname varchar(50), Link varchar(50), Code varchar(50)) insert into @t (id,idname,Link,Code) values (1,'1_1','1','900055') insert into @t (id,idname,Link,Code) values (1,'1_1','2','900055') insert into @t (id,idname,Link,Code) values (3,'3_1','3','900051') insert into @t (id,idname,Link,Code) values (4,'4_1','4','900050') select id as [@id],idname as [@idname] , (select Link as [@link],Code as [@Code] from @t where id = x.id for xml path(N'serv_code')) from (select distinct id,idname from @t) x for xml path(N'client'), root(N'clients'); результат <clients> <client id="1" idname="1_1"><serv_code link="1" Code="900055"/><serv_code link="2" Code="900055"/></client> <client id="3" idname="3_1"><serv_code link="3" Code="900051"/></client> <client id="4" idname="4_1"><serv_code link="4" Code="900050"/></client> </clients> понимаю что все корректно, но почему он перекодирует знаки больше и меньше? |
10 апр 15, 16:32 [17499625] Ответить | Цитировать Сообщить модератору |
Glory Member Откуда: Сообщений: 104760 |
Потому что эти знаки - спецсимволы. |
||
10 апр 15, 16:33 [17499637] Ответить | Цитировать Сообщить модератору |
marvel Member Откуда: Сообщений: 1066 |
да понятно, а можно сделать с переносами, вот так:<clients> <client id="1" idname="1_1"> <serv_code link="1" Code="900055"/> <serv_code link="2" Code="900055"/> </client> <client id="3" idname="3_1"> <serv_code link="3" Code="900051"/> </client> <client id="4" idname="4_1"> <serv_code link="4" Code="900050"/> </client> </clients> |
10 апр 15, 16:34 [17499644] Ответить | Цитировать Сообщить модератору |
felix_ff Member Откуда: Moscow Сообщений: 1692 |
declare @t table (id int,idname varchar(50), Link varchar(50), Code varchar(50)) insert into @t (id,idname,Link,Code) values (1,'1_1','1','900055') insert into @t (id,idname,Link,Code) values (1,'1_1','2','900055') insert into @t (id,idname,Link,Code) values (3,'3_1','3','900051') insert into @t (id,idname,Link,Code) values (4,'4_1','4','900050') select id as [@id],idname as [@idname] , (select Link as [@link],Code as [@Code] from @t where id = x.id for xml path(N'serv_code'), type) from (select distinct id,idname from @t) x for xml path(N'client'), root(N'clients'); |
||
10 апр 15, 16:39 [17499668] Ответить | Цитировать Сообщить модератору |
marvel Member Откуда: Сообщений: 1066 |
Спасибо! |
10 апр 15, 16:42 [17499687] Ответить | Цитировать Сообщить модератору |
Все форумы / Microsoft SQL Server | ![]() |