Apologies on the last post. I did not see FOR XML and was thinking of other
SQL capabilities.
FOR XML creates a valid XML snippet, without root tags. This gives you a
couple of choices.
1. Create templates that supply root tags
2. Supply root tags in your program
For XML input into SQL Server, you WILL end up with a blow up, as mentioned
in the prior response.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"VK" wrote:
> Hi,
> Will SQL XML (when we use FOR XML) perform check to make sure that XML
> document is in proper form or do we have to use a third party s/w like
> Altova to check for correctly created XML document?
> Many thanks for your time.
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!
>
Let me clarify this a bit further.
FOR XML in most cases (except for invalid characters and when using the
xmltext directive in EXPLICIT mode) will generate well-formed fragments. You
can set a root property on your provider (ADO, ADO.net, or the HTTP ISAPI)
to have it wrapped.
When you use sp_xml_preparedocument to parse incoming XML data, you will get
an error message if the parsing fails. So it does not quite explode :-).
Best regards
Michael
"Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@.comcast.netNoSpamM> wrote
in message news:B30C9949-8C15-46CE-826B-4961014B9B19@.microsoft.com...[vbcol=seagreen]
> Apologies on the last post. I did not see FOR XML and was thinking of
> other
> SQL capabilities.
> FOR XML creates a valid XML snippet, without root tags. This gives you a
> couple of choices.
> 1. Create templates that supply root tags
> 2. Supply root tags in your program
> For XML input into SQL Server, you WILL end up with a blow up, as
> mentioned
> in the prior response.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> ***************************
> Think Outside the Box!
> ***************************
> "VK" wrote:
Showing posts with label updated. Show all posts
Showing posts with label updated. Show all posts
Monday, March 12, 2012
FOR XML? UPDATED ANSWER (WAS: Newbie question...)
Apologies on the last post. I did not see FOR XML and was thinking of other
SQL capabilities.
FOR XML creates a valid XML snippet, without root tags. This gives you a
couple of choices.
1. Create templates that supply root tags
2. Supply root tags in your program
For XML input into SQL Server, you WILL end up with a blow up, as mentioned
in the prior response.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"VK" wrote:
> Hi,
> Will SQL XML (when we use FOR XML) perform check to make sure that XML
> document is in proper form or do we have to use a third party s/w like
> Altova to check for correctly created XML document?
> Many thanks for your time.
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
>Let me clarify this a bit further.
FOR XML in most cases (except for invalid characters and when using the
xmltext directive in EXPLICIT mode) will generate well-formed fragments. You
can set a root property on your provider (ADO, ADO.net, or the HTTP ISAPI)
to have it wrapped.
When you use sp_xml_preparedocument to parse incoming XML data, you will get
an error message if the parsing fails. So it does not quite explode :-).
Best regards
Michael
"Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@.comcast.netNoSpamM> wrote
in message news:B30C9949-8C15-46CE-826B-4961014B9B19@.microsoft.com...
> Apologies on the last post. I did not see FOR XML and was thinking of
> other
> SQL capabilities.
> FOR XML creates a valid XML snippet, without root tags. This gives you a
> couple of choices.
> 1. Create templates that supply root tags
> 2. Supply root tags in your program
> For XML input into SQL Server, you WILL end up with a blow up, as
> mentioned
> in the prior response.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> ***************************
> Think Outside the Box!
> ***************************
> "VK" wrote:
>
SQL capabilities.
FOR XML creates a valid XML snippet, without root tags. This gives you a
couple of choices.
1. Create templates that supply root tags
2. Supply root tags in your program
For XML input into SQL Server, you WILL end up with a blow up, as mentioned
in the prior response.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"VK" wrote:
> Hi,
> Will SQL XML (when we use FOR XML) perform check to make sure that XML
> document is in proper form or do we have to use a third party s/w like
> Altova to check for correctly created XML document?
> Many thanks for your time.
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
>Let me clarify this a bit further.
FOR XML in most cases (except for invalid characters and when using the
xmltext directive in EXPLICIT mode) will generate well-formed fragments. You
can set a root property on your provider (ADO, ADO.net, or the HTTP ISAPI)
to have it wrapped.
When you use sp_xml_preparedocument to parse incoming XML data, you will get
an error message if the parsing fails. So it does not quite explode :-).
Best regards
Michael
"Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@.comcast.netNoSpamM> wrote
in message news:B30C9949-8C15-46CE-826B-4961014B9B19@.microsoft.com...
> Apologies on the last post. I did not see FOR XML and was thinking of
> other
> SQL capabilities.
> FOR XML creates a valid XML snippet, without root tags. This gives you a
> couple of choices.
> 1. Create templates that supply root tags
> 2. Supply root tags in your program
> For XML input into SQL Server, you WILL end up with a blow up, as
> mentioned
> in the prior response.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> ***************************
> Think Outside the Box!
> ***************************
> "VK" wrote:
>
Friday, February 24, 2012
for each record updated
Currently in my database I have Widgets. These Widgest can be linked
together through keys in a Link table. Think in terms of hierarchy. A
parent Widget has child Widgets linked to it. These child Widgets when
linked take on properties(field values) of the parent Widgets. I have a
trigger that fires when a property(field) is changed in the parent
Widget that changes that property(field) in all the child Widgets. I
want to add to that trigger so that the trigger will also insert a new
record into a log table for each record updated. Here is some example
code:
SELECT @.widget_id = widget_id, @.status = status
FROM inserted
BEGIN
update widget
set status = @.status, updated_date = @.current_date
where widget_id in (select linked_id
from link
where topic = 'LINK'
and log_type = 'CLONE'
and id = @.widget_id)
and defect_status != 'Complete'
END
For each of these children widgets updated I want to insert a record
into a log table with the widget_id and the linked_id as fields. Anyone
have any ideas. I hope this is somewhat clear.
JakeHello Jake !
To direct you to the right solution some DDL would be very nice,
because we don=B4t know your table structure and how the data is stored.
http://www.aspfaq.com/5006
After posting we will be pleased to help you :-D
HTH, Jens Suessmeyer.|||> SELECT @.widget_id = widget_id, @.status = status
> FROM inserted
Triggers are in their essence set-based. You just made yours lose that
wonderful ability.
You don't need variables to propagate changes from one table to another:
update <destination_table>
set <dest_column_1> = <src_column_1>
..
from inserted
<join> <destination_table>
on <destination_table>.<common_key> =
inserted.<common_key>
ML
together through keys in a Link table. Think in terms of hierarchy. A
parent Widget has child Widgets linked to it. These child Widgets when
linked take on properties(field values) of the parent Widgets. I have a
trigger that fires when a property(field) is changed in the parent
Widget that changes that property(field) in all the child Widgets. I
want to add to that trigger so that the trigger will also insert a new
record into a log table for each record updated. Here is some example
code:
SELECT @.widget_id = widget_id, @.status = status
FROM inserted
BEGIN
update widget
set status = @.status, updated_date = @.current_date
where widget_id in (select linked_id
from link
where topic = 'LINK'
and log_type = 'CLONE'
and id = @.widget_id)
and defect_status != 'Complete'
END
For each of these children widgets updated I want to insert a record
into a log table with the widget_id and the linked_id as fields. Anyone
have any ideas. I hope this is somewhat clear.
JakeHello Jake !
To direct you to the right solution some DDL would be very nice,
because we don=B4t know your table structure and how the data is stored.
http://www.aspfaq.com/5006
After posting we will be pleased to help you :-D
HTH, Jens Suessmeyer.|||> SELECT @.widget_id = widget_id, @.status = status
> FROM inserted
Triggers are in their essence set-based. You just made yours lose that
wonderful ability.
You don't need variables to propagate changes from one table to another:
update <destination_table>
set <dest_column_1> = <src_column_1>
..
from inserted
<join> <destination_table>
on <destination_table>.<common_key> =
inserted.<common_key>
ML
Sunday, February 19, 2012
FOR and AFTER
Someone pls enlighten me...
I understand that FOR TRIGGERS would be executed concurrently as the table is being updated/inserted/deleted
&
AFTER TRIGGER would only be executed after the UPDATE/INSERT/DELETE operation has been completed...am i right?I never heard of FOR TRIGGERS. I only know about
BEFORE TRIGGER (not supported by MSSQL, as far as I know)
AFTER TRIGGER
INSTEAD OF TRIGGER
Where did you hear about FOR triggers ?|||ok sorry i didn't mean FOR triggers..
what i meant was ..whats the difference between the following 2.
ALTER TRIGGER SendMsgs ON asiapac702_test.dbo.tblCustServiceHistoryHdr FOR UPDATE
AS...
ALTER TRIGGER SendMsgs ON asiapac702_test.dbo.tblCustServiceHistoryHdr AFTER UPDATE
AS...|||Ok, now I get it.
As far as I can understand from the documentation, FOR and AFTER are synonyms, from a syntax point of view.
I did some testing, and found no differences between
create trigger tai_t on t FOR insert as begin select 1 end
create trigger tai_t2 on t AFTER insert as begin select 1 end
Probably this has something to do with being ANSI/ISO or whatever compliant.
I understand that FOR TRIGGERS would be executed concurrently as the table is being updated/inserted/deleted
&
AFTER TRIGGER would only be executed after the UPDATE/INSERT/DELETE operation has been completed...am i right?I never heard of FOR TRIGGERS. I only know about
BEFORE TRIGGER (not supported by MSSQL, as far as I know)
AFTER TRIGGER
INSTEAD OF TRIGGER
Where did you hear about FOR triggers ?|||ok sorry i didn't mean FOR triggers..
what i meant was ..whats the difference between the following 2.
ALTER TRIGGER SendMsgs ON asiapac702_test.dbo.tblCustServiceHistoryHdr FOR UPDATE
AS...
ALTER TRIGGER SendMsgs ON asiapac702_test.dbo.tblCustServiceHistoryHdr AFTER UPDATE
AS...|||Ok, now I get it.
As far as I can understand from the documentation, FOR and AFTER are synonyms, from a syntax point of view.
I did some testing, and found no differences between
create trigger tai_t on t FOR insert as begin select 1 end
create trigger tai_t2 on t AFTER insert as begin select 1 end
Probably this has something to do with being ANSI/ISO or whatever compliant.
Subscribe to:
Posts (Atom)