USING THE XML DATA TYPE IN TABLES

USING THE XML DATA TYPE IN TABLES these work fine INSERT INTO xml_tab VALUES( ) INSERT INTO xml_tab VALUES(N ) so does this (if first cast to varchar/nvarchar) DECLARE @v SQL_VARIANT SET @v = N INSERT INTO xml_tab VALUES(CAST(@v AS varchar(max))) this fails at the insert statement DECLARE @SOMENUM FLOAT SET @SOMENUM = 3.1416 INSERT INTO xml_tab VALUES(CAST(@SOMENUM as XML)) Although we ve only stored well-formed XML documents in the XML data type column so far, we can also use this column to store document fragments or top-level text nodes. This is useful because we can store the results of a SELECT…FORXMLquery or XQuery results, which may not be complete documents, in an XML data type column. However, the documents or fragments must abide by XML well-formedness rules. Listing 8-2 shows some examples. Listing 8-2: Inserting XML Data into a Table CREATE TABLE xml_tab( the_id INTEGER PRIMARY_KEY IDENTITY, xml_col XML) GO ok, complete document INSERT INTO xml_tab VALUES( ) ok, document fragment though it s not a single well-formed document (two root elements) INSERT INTO xml_tab VALUES( ) ok, text element INSERT INTO xml_tab VALUES( The Window and Shade Store ) error, not well-formed INSERT INTO xml_tab VALUES( The Window & Shade Store ) error, not well-formed INSERT INTO xml_tab VALUES( ) There is no implicit conversion from the XML data type to any other data types, but the CAST or CONVERT operators do convert between any of

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

Bookmark the permalink.

Comments are closed.