Next, I will introduce a feature of using XML technology to merge rows and columns in SQL SERVER2005.
DECLARE @ idoc intDECLARE @ doc xml
SET @ doc ='
'
EXEC sp_xml_preparedocument @ idoc OUTPUT, @ doc
SELECT csif_cStateIDFrom openxml (@ idoc, '/condition/state ')WITH (csif_cStateID varchar (15 ))EXEC sp_xml_removedoc
Tags: case AAA Compact SOC ISS ble Article char = = SQL FOR XML also has a way of writing (with tag and union all, simple and easy to understand) Test environment: SQL, R2, 2010, 2012, 2014, etc. Declare @agent table (agentid int, Fname varchar (5), SSN varchar (one)) inser
Copy Code code as follows:
--Create a test table
DECLARE @Users TABLE
(
ID INT IDENTITY (1,1),
UserInfo XML
)
---insert test data
DECLARE @xml XML
SET @xml = '
INSERT into @Users (UserInfo) VALUES (@xml)
--Insert a single node, (type: As First,as last,after (
Sometimes it may be useful to associate or analyze data from SQL Server to other departments at once, a requirement that is certainly simple for SSIS, but a lot of times it makes a fuss to create a SSIS package just by exporting the data one at a time, while the SQL The Import Export tool for the server there are a lot of bugs, the easiest way is to bcp.
Data exported to
Find all non-xml Indexes
Find all non-xml Indexes
The Code is as follows:DECLARE cur CURSORSELECT[Object_name] = s. name + '.' + OBJECT_NAME (A. object_id ),B. nameFROM sys. dm_db_index_physical_stats (DB_ID ('adventureworks'), NULL, null, null) ASJOIN sys. indexes AS BOn a. [object_id] = B. [object_id]And a. [index_id] = B. [index_id]JOIN sys. objects AS oOn a. [object_id] = o. [object_id]JOIN sys. sche
Sometimes the need to export data from SQL Server to other departments may be correlated or analyzed, which is of course very simple for SSIS, but many times it takes a lot of time to simply export the data and create an SSIS package that makes a fuss, while the SQL The Import and Export tool for the server where the bugs are still pretty much, the simplest way is bcp. Data export to XMLAfter
Label:Recently while working with data migration,got an error while running a following query where Server2 have beed added as Li nked server. Select
* from
Server1.Database1.dbo.Table1
WHERE Column1 not in
(select Column1 from Server2.Database2.dbo.Table1)
GO
-Error raised while run above query
"XML data type was not supported in Dist ributed queries. Remote object ' Server2.Database2.dbo.Table1 ' has XML
Tags: xml generation XML pen definition end ISP list var body---------The following is the build XML1 Main Table query definitionSELECT t.c.query (' MID '). Value ('. [ 1] ', ' int ') as MID,T.c.query (' EventName '). Value ('. [ 1] ', ' varchar (+) ') as EventName,@NowDate as CreateDate,T.c.query (' begindate '). Value ('. [ 1] ', ' datetime ') as Begindate,T.c.
Label:Tools to use:
Sql server
Java
MyBatis
First step: Create a function to get the data in the XMLCREATE function create_table (@str XML) returns @tb table (SourceID varchar) asbegin INSERT INTO @tb SELECT v.value (' @sourceId [1] ', ' VARCHAR ') as SourceIDfrom @str
, First, through the cast command to convert the XMLData to XML type format, and then through its Value property decomposition, you can see the same as above,/list/item/no is hierarchical, and the last as no is to give the field to get a name.cast as XML). Value ('(/list/item/no/text ()) [1]','NVARCHAR ' as NoThrough the above sentence can easily parse out the
1. Get the number of nodes under a node in the XML typeDECLARE @xmlXMLSET @xml = '';SELECT @xml. Value ('count (/parameters/parameter)','int')2. Turn XML into tableDECLARE @xmlXMLSET @xml = '';SELECTT.c.query ('.'). Value ('(//@name) [1]','
Tags: sele port this SQ txt des ber lines andThis article transferred from: Https://stackoverflow.com/questions/44754356/sql-create-xml-how-to-set-unicode-utf-8 I found a solution via another. (Don ' t remember which website I found it) See code below. This code would export my file in Utf-8-bom encoding.
DECLARE @OLE INT EXECUTE sp_oacreate ' ADODB. Stream ', @OLE OUTPUT DECLARE @Text
server|xml| Insert | Data we know that XML types are added to SQL Server 2005, which means that you can specify a column XML type when you create a table, such as:
CREATE TABLE Customers
(
Name VARCHAR not NULL PRIMARY KEY,
Description X
Label:SQL Server supports XML types starting from 2005, which is useful for late changes. A one-to-many relationship turns into a many-to-many relationship at a later stage, and the XML type is a good choice. 1. Create test data Create a table -- CREATE table with XML Type column
tableint, Info xml Inserti
Label:CREATE
FUNCTION [dbo].[ GETXXXXXXXXX]
(
@productCategoryId INT, @SplitChar varchar
)
RETURNS NVARCHAR (MAX)
as
BEGIN
DECLARE @returnProductCategory NVARCHAR ( MAX) =n '
/*--Note that the CTE expression must be preceded by a semicolon ";" To separate the code, it is suggested to add a semicolon ";" in front of the--*/
;With CTE as (
SELECT
ProductCategoryID from
Tidebuy_SCM_Test.dbo.xxxx_xxxx pare
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.