I think a lot of people know that in Oracle, stored procedures can be passed in an array (such as int[]), that is, you can pass multiple records to the data to update together. Reduce the number of requests to the database.
But what about SQL Server? Bulk INSERT This is a lot of people know, I also know, but unfortunately, I have never used, only to guide the data will be considered, but the Guide data DTS is not more convenient?
An item on hand, ther
SQL FOR XML alternative notation (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)) insert into @agent Select 1, ' Vimal ', ' 123-23-4521 ' UNION ALL
Some Opinions on SQL Server 2000's XML supportThis article mainly discusses similar statements of "select Field 1, Field 2,..., field N from table or multi-table joint query where condition for XML auto ".
When I used the preceding statements to generate XML data, I found some rules for
First, create a table:
CopyCode The Code is as follows: use [IP]
Go
/***** Object: Table [DBO]. [sitedata] script Date: 17:41:11 ******/
Set ansi_nulls on
Go
Set quoted_identifier on
Go
Set ansi_padding on
Go
Create Table [DBO]. [sitedata] (
[ID] [int] identity (1, 1) not null,
[Sitename] [varchar] (50) Collate chinese_prc_ci_as not null,
[Siteadd] [varchar] (100) Collate chinese_prc_ci_as not null,
[Ba
Label:Original: Export data to XML and JSON in SQL ServerSometimes 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
1.xml.exist
Enter an XQuery expression that returns either 0,1 or null. 0 means not present, 1 indicates existence, NULL indicates NULL input
2.xml.value
Enter an XQuery expression that returns a SQL Server scalar value
3.xml.query
Enter an XQuery expression that returns a SQL Server XML type stream
4.xml.nodes
Enter an XQuery expression that returns a set of row
First, Introduction
One of the major changes in Microsoft SQL Server 2005 is the inclusion of XML data types. This data type is the first class type, just like INT or VARCHAR, and SQL Server 2005 allows you to query and process this data type in-place using a series of XML-s
SQL for xml query sample, xmlsample
Sample 1:
declare @x xml select @x='
select @x.query('/ArrayOfScheduledTime/ScheduledTime/RecurrenceType')/*
Select o. value ('recurrencetype [1] ', 'varchar (20)') 'recurrencetype 'from (select @ x 'X') t cross apply x. nodes ('/ArrayOfScheduledTime/ScheduledTime') x (o)/* Rec
I often want to use data set parameters for processing stored procedures, but SQL server does not provide such services.
Oracle seems to have, and this is the gap ~~~
There is no way for SQL Server to be used in this way.
Although SQL server does not explicitly provide a data set parameter, we can use some of its functions to implement it.
follows:SELECT Hobbyid as ' MyCode ', hname as ' MyName ' from @hobby for XML PATH (' Myhobby ')So at this point the node name of our column will also be programmed with our custom name Oh! Now that we can customize the nodes and columns of the row, can we build the output that we like? Or look at the code:SELECT ' [' +hname+ '] ' from @hobby for XML PATH (')Yes, we can also define the output format of a S
follows:SELECT Hobbyid as ' MyCode ', hname as ' MyName ' from @hobby for XML PATH (' Myhobby ')So at this point the node name of our column will also be programmed with our custom name Oh! Now that we can customize the nodes and columns of the row, can we build the output that we like? Or look at the code:SELECT ' [' +hname+ '] ' from @hobby for XML PATH (')Yes, we can also define the output format of a S
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
Data exported to XML
After SQL Server 2005, a FOR XML clause is provided to natively support XML in a relational database. This command enables you to convert a two-dimensional relational result set to XML, which can be saved as
-----------------------define a cursor variable------------------------------------------DECLARE @propertyid INTDECLARE @propertyname VARCHAR (50)DECLARE @xml NVARCHAR (1000)DECLARE top3_cursor Cursor SCROLL for--------------------------defines the end of the cursor-----------------------------SELECT s.id, S.name, CAST (Propertyvalueschema as VARCHAR) Propertyval
field (the default page), assigning and taking values using the set label of the core tag Library of the C alias Target object to be assigned, remember to use the EL expression, corresponding to the ID name above, the property name of the object to be assigned value Remember that the objects and values in the tag library are basically stored in the domain, and the default is page. The name of the object to be evaluated using the GetProperty tag Name property to go to value CatchVar= "ErrorInfo"
Tags: style blog http ar color OS sp for onOriginal: Application of the "T-SQL Series" for XML PATH statementDECLARE @TempTable TABLE(UserIDINT, UserNameNVARCHAR( -) );INSERT into @TempTable(UserID, UserName)VALUES(1,'a' )INSERT into @TempTable(UserID, UserName)VALUES(2,'b' ) SELECTUserID, UserName from @TempTable forXML PATH--In fact, the parameter within the path () is the control node name.SEL
ObjectiveIn SQL Server sometimes we need to descendant a table in the past, then we can batch update in the stored procedure, get the corresponding data in batches.But the parameters of the stored procedure are fixed, so here we can work around the parameters of the XML type, and then convert it directly into the table we need in the stored procedure.Specific imp
the code:SELECT '[ '+hname+' ]' from @hobby for XML PATH (") Yes, we can also define the output format of a String type field by using the symbol + number. The results are as follows:[climbing] [swimming] [food]So how do other types of columns customize? That's OK, let's convert them to string type! For example:SELECT‘{‘+str (Hobbyid) + ' } ",[ ' +hname+" ] "from @hobby forxml path ( ")
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.