sqlxml

Concatenating xml values when selecting by XQuery in T-SQL

风流意气都作罢 提交于 2019-12-04 06:24:48
This is my sample XML: <root> <element> <subelement> <value code="code1">value1</value> <value code="code2">value2</value> </subelement> </element> </root> And this is my test query: DECLARE @tempTable TABLE ( ValueCode nvarchar(MAX), Value nvarchar(MAX) ) DECLARE @xml XML select @xml = cast(c1 as xml) from OPENROWSET (BULK 'C:\test.xml', SINGLE_BLOB) as T1(c1) INSERT INTO @tempTable SELECT Tbl.Col.value('subelement[1]/@code', 'NVARCHAR(MAX)'), Tbl.Col.value('subelement[1]', 'NVARCHAR(MAX)') FROM @xml.nodes('//element') Tbl(Col) SELECT * FROM @tempTable The query, when executed, gives out a

SqlDataReader are these two the same Which one is faster

感情迁移 提交于 2019-12-04 03:38:39
问题 I am working with SqlXml and the stored procedure that returns a xml rather than raw data. How does one actually read the data when returned is a xml and does not know about the column names. I used the below versions and have heard getting data from SqlDataReader through ordinal is faster than through column name. Please advice on which is best and with a valid reason or proof sqlDataReaderInstance.GetString(0); sqlDataReaderInstance[0]; 回答1: and have heard getting data from SqlDataReader

Get comma separated values from an xml in SQL

浪子不回头ぞ 提交于 2019-12-02 16:00:51
问题 I am calling Scalar UDF from a stored procedure to get a column value. Inside the scalar UDF I have an xml and I have to get the comma separated values of a particular node. I used Cross apply but it caused huge performance bottleneck because stored procedure is actually used to fetch reports. There is a table [Traveler] which has a field ID, BookingID(can be duplicate) and FareDetails. Inside the FareDetails we are storing the xml. The logic inside UDF is as follows : 1st Solution , Using

Multiple rows in one column SQL Server

℡╲_俬逩灬. 提交于 2019-12-02 01:52:39
问题 I want to concatenate multiple rows in one column. I found many examples in Internet but does not working for me. What am I doing wrong? SELECT UserID, STUFF((SELECT '; ' + Email.Email From Email where UserEmail.EmailID = Email.ID for xml path('')),1,1, '') AS Emails From UserEmail where UserID = 1 I'm still having the information like this UserID Email 1 abc@yahoo.com 1 cde@gmail.com --EDIT-- Ok, I did this change but still having 2 rows. If I apply distinct this will fix my problem but why

SqlDataReader are these two the same Which one is faster

旧时模样 提交于 2019-12-01 19:54:14
I am working with SqlXml and the stored procedure that returns a xml rather than raw data. How does one actually read the data when returned is a xml and does not know about the column names. I used the below versions and have heard getting data from SqlDataReader through ordinal is faster than through column name. Please advice on which is best and with a valid reason or proof sqlDataReaderInstance.GetString(0); sqlDataReaderInstance[0]; and have heard getting data from SqlDataReader through ordinal is faster than through column name Both your examples are getting data through the index

XML data type method “value” must be a string literal [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 16:55:37
This question already has an answer here: The argument 1 of the XML data type method “value” must be a string literal 2 answers How to change my query so that this error doesn't happen: XML data type method “value” must be a string literal T-SQL code: Declare @Count Int = 1 While(@count <= @j) Begin insert into mytable ([Word]) Select ([XmlColumn].value(N'word['+Cast(@Count as nvarchar(2))+']/@Entry','nvarchar(max)')) from OtherTable WHERE ID=2 You cannot concatenate variables as strings in this way for the value method. You need to use sql:variable("@VariableName") . So your example would be

XML data type method “value” must be a string literal [duplicate]

早过忘川 提交于 2019-12-01 14:39:41
问题 This question already has answers here : The argument 1 of the XML data type method “value” must be a string literal (2 answers) Closed 5 years ago . How to change my query so that this error doesn't happen: XML data type method “value” must be a string literal T-SQL code: Declare @Count Int = 1 While(@count <= @j) Begin insert into mytable ([Word]) Select ([XmlColumn].value(N'word['+Cast(@Count as nvarchar(2))+']/@Entry','nvarchar(max)')) from OtherTable WHERE ID=2 回答1: You cannot

How to split a string in sql server 2008 using stored procedure and insert the data to table

耗尽温柔 提交于 2019-12-01 10:57:30
I want to split a string in this format Quote: "date=10/10/2000|age=13^date=01/01/2001|age=12^date=02/02/2005|age=8" . Actually this string is only a sample one my original string is very large . i am not getting a point that if i break this string than how many variables i have to make to capture the data also after splitting the string i want that to be inserted into data table containing columns as date and age? What concept do i use?(I am getting this string from a web service) Thanks in advance.. In general, I'd suggest to write a CLR function which split strings by regex or SQL table

How to split a string in sql server 2008 using stored procedure and insert the data to table

♀尐吖头ヾ 提交于 2019-12-01 08:57:13
问题 I want to split a string in this format Quote: "date=10/10/2000|age=13^date=01/01/2001|age=12^date=02/02/2005|age=8" . Actually this string is only a sample one my original string is very large . i am not getting a point that if i break this string than how many variables i have to make to capture the data also after splitting the string i want that to be inserted into data table containing columns as date and age? What concept do i use?(I am getting this string from a web service) Thanks in

SQL 2012 - iterate through an XML list (better alternative to a WHILE loop)

邮差的信 提交于 2019-12-01 06:10:57
Using SQL 2012 & getting XML passed into a stored procedure that must take that input & write a row to the table for each of the items that is in a section of the XML that is passed to the stored procedure. The XML looks like: <MyXML> <MyMsg>My Text Message</MyMsg> <MsgTime>2013-09-25 10:52:37.098</MsgTime> <SendToList> <SendTo>John</SendTo> <SendTo>James</SendTo> <SendTo>Rob</SendTo> <SendTo>Pete</SendTo> <SendTo>Sam</SendTo> </SendToList> </MyXML> The output of the stored procedure should be 5 rows inserted into a table (one for each SendTo above), and each having the same value in the MyMsg