Stumped again
  Home FAQ Contact Sign in
microsoft.public.sqlserver.xml only
 
Advanced search
POPULAR GROUPS

more...

microsoft.public.sqlserver.xml Profile…
 Up
Stumped again         


Author: Leon Mayne
Date: Sep 4, 2008 01:48

I have two tables, one holding task details and the Id of the employee
they are assigned to, and another table holding an XML representation of
an email to send to the employee telling them they have one or more
tasks assigned to them. For example:

declare @tblEmail table
(
intEmployeeId int not null,
xmlEmail XML
)

insert into @tblEmail
select 1, ''
insert into @tblEmail
select 2, ''

declare @tblTask table
(
intAssignedTo int,
txtTitle varchar(255)
)
Show full article (1.06Kb)
7 Comments
Re: Stumped again         


Author: Martin Honnen
Date: Sep 4, 2008 06:23

Leon Mayne wrote:
> I have two tables, one holding task details and the Id of the employee
> they are assigned to, and another table holding an XML representation of
> an email to send to the employee telling them they have one or more
> tasks assigned to them. For example:
>
> declare @tblEmail table
> (
> intEmployeeId int not null,
> xmlEmail XML
> )
>
> insert into @tblEmail
> select 1, ''
> insert into @tblEmail
> select 2, ''
>
> declare @tblTask table
> (
> intAssignedTo int, ...
Show full article (2.77Kb)
no comments
Re: Stumped again         


Author: Martin Honnen
Date: Sep 4, 2008 06:45

Leon Mayne wrote:
> How can I perform an insert into the tag of the XML column
> containing details like:
>
>

Dear Employee 1, You have been assigned the following tasks:

> Task 1

> Task 2

> Task 3

> Task 4


>
> And
>

Dear Employee 2, You have been assigned the following tasks:

> Task 5


>
> Can anyone help?

Here is a second attempt:
Show full article (2.14Kb)
no comments
RE: Stumped again         


Author: Bob
Date: Sep 4, 2008 09:12

Well it aint pretty but it does work in SQL 2005. I came up against the
XQuery / xml limitaton pretty early on.

SET NOCOUNT ON

declare @tblEmail table
(
intEmployeeId int not null,
xmlEmail XML
)

insert into @tblEmail
select 1, ''
insert into @tblEmail
select 2, ''

declare @tblTask table
(
intAssignedTo int,
txtTitle varchar(255)
)
Show full article (2.94Kb)
no comments
Re: Stumped again         


Author: Martin Honnen
Date: Sep 4, 2008 09:26

Bob wrote:
> UPDATE e
> SET xmlEmail.modify('insert
{sql:column("t.txtTitle")}

> into (/email/body/p)[1]')
> I couldn't quite get your tags right ( I've used

instead of

> ) but hopefully the technique will work for you?

That can be fixed by using

SET xmlEmail.modify(
'insert (
,text{sql:column("t.txtTitle")}) into
(/email/body/p)[1]')

to construct a br element plus a text node.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
no comments
Re: Stumped again         


Author: Damien
Date: Sep 4, 2008 11:21

Cheers Martin!

"Martin Honnen" wrote:
Show full article (0.59Kb)
no comments
Re: Stumped again         


Author: Leon Mayne
Date: Sep 5, 2008 01:29

Thanks everyone.
no comments
RE: Stumped again         


Author: Bob
Date: Sep 8, 2008 04:31

I had another crack at this and got the following much cleaner solution:

SET NOCOUNT ON

DECLARE @tblEmail TABLE
(
intEmployeeId INT NOT NULL,
xmlEmail XML
)

INSERT INTO @tblEmail
SELECT 1, ''
INSERT INTO @tblEmail
SELECT 2, ''

DECLARE @tblTask TABLE
(
intAssignedTo INT,
txtTitle VARCHAR(255)
)
Show full article (2.35Kb)
no comments