Turn XML column into SQL tables [closed] - sql-server

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have this problem that I don't know how to solve.
First I've imported the XML data to a SQL table named Sheet1 to column MENUXML. A sample from the XML is:
<DADOSNOTAALTA titulo="Externa E6020731-INT NEFROLOGIA (27-10-2006*1:07:17 PM)" mostra="1" liga="novaalta.aspx?x=DADOSNOTAALTA" versao="1" data="27-10-2006" hora="1:09:05 PM" autor="CH" publica="" episodio="6020731" especialidade="SCI" interna="0">
<DTALTA titulo="Data da Alta" valor="27-10-2006, 12:59" />
<DESTINOT titulo="" valor="Consulta externa" />
<DESTINOD titulo="Obs:" valor="HGSA 31/10/2006" />
<MTADM titulo="" valor="DISFUNÇÃO ENXERTO RENAL
CREATININA 1,4 -2,2 AGORA 1,7" />
<RESUMO titulo="" valor="BIOPSIA RENAL - SINAIS DE NTA, SEM SINAIS NA MICROSC. ÓPTICA DE REJEIÇÃO AGUDA
C4D POSITIVO PERI-TUBULAR" />
<DIAGNO titulo="" valor="Transplante com rim de dador cadáver COM DISFUNÇÃO TRANSITÓRIA.
Transplante pâncreas
" />
<TRATAM titulo="" valor="Tacrolimus 5 + 4 mg, 12/12 horas
Sirolimus 2mg dia
Prednisolona 20mg, manhã
Valganciclovir 450mg
Omeprazol 20 mg dia
Bactrim 1 compr./dia
Epo B 6000 / 2 vezes /semana SC.
Ácido acetilsalicílico 100mg dias alternados
Carbonato de cálcio 2 gr, /dia
" />
<PROG titulo="" valor="" />
<PROPI titulo="" valor="" />
<MONIT titulo="" valor="FUNÇÃO RENAL E PANCREATICA E NIVEIS FÁRMACOS" />
<ORIENT titulo="" valor="cONSULTA EXTERNA TR RIM-PANCREAS" />
</DADOSNOTAALTA>
Then I've created a new table named Dados with the following columns:
dados_nota, destino_tratamento, destino_doente,
metodo_admissao, resumo, diagnostico, tratamento,
prog, propi, monitorizacao, orientacao
These are all present in the XML.
Table from where i want to extract the XML
Table where i want to save the transformed data
Now the problem is that i don't know how to make SQL Server read the the XML direct from the column and transfer it to the columns in the new database.
Kind regards

Your question might be clear for you, but it is not clear at all...
... they [columns] are all present in the XML...
Well, one might guess, but this is up to you :-D
Try this:
DECLARE #xml XML=
N'<DADOSNOTAALTA titulo="Externa E6020731-INT NEFROLOGIA (27-10-2006*1:07:17 PM)" mostra="1" liga="novaalta.aspx?x=DADOSNOTAALTA" versao="1" data="27-10-2006" hora="1:09:05 PM" autor="CH" publica="" episodio="6020731" especialidade="SCI" interna="0">
<DTALTA titulo="Data da Alta" valor="27-10-2006, 12:59" />
<DESTINOT titulo="" valor="Consulta externa" />
<DESTINOD titulo="Obs:" valor="HGSA 31/10/2006" />
<MTADM titulo="" valor="DISFUNÇÃO ENXERTO RENAL
CREATININA 1,4 -2,2 AGORA 1,7" />
<RESUMO titulo="" valor="BIOPSIA RENAL - SINAIS DE NTA, SEM SINAIS NA MICROSC. ÓPTICA DE REJEIÇÃO AGUDA
C4D POSITIVO PERI-TUBULAR" />
<DIAGNO titulo="" valor="Transplante com rim de dador cadáver COM DISFUNÇÃO TRANSITÓRIA.
Transplante pâncreas
" />
<TRATAM titulo="" valor="Tacrolimus 5 + 4 mg, 12/12 horas
Sirolimus 2mg dia
Prednisolona 20mg, manhã
Valganciclovir 450mg
Omeprazol 20 mg dia
Bactrim 1 compr./dia
Epo B 6000 / 2 vezes /semana SC.
Ácido acetilsalicílico 100mg dias alternados
Carbonato de cálcio 2 gr, /dia
" />
<PROG titulo="" valor="" />
<PROPI titulo="" valor="" />
<MONIT titulo="" valor="FUNÇÃO RENAL E PANCREATICA E NIVEIS FÁRMACOS" />
<ORIENT titulo="" valor="cONSULTA EXTERNA TR RIM-PANCREAS" />
</DADOSNOTAALTA>';
SELECT #xml.value(N'/DADOSNOTAALTA[1]/#titulo',N'nvarchar(max)') AS dadosnota_titulo
,#xml.value(N'/DADOSNOTAALTA[1]/#mostra',N'int') AS dadosnota_mostra --some int value
--ommited more attributes
,#xml.value(N'/DADOSNOTAALTA[1]/DTALTA[1]/#titulo',N'nvarchar(max)') AS dtalta_titulo
,#xml.value(N'/DADOSNOTAALTA[1]/DTALTA[1]/#valor',N'nvarchar(max)') AS dtalta_valor --bad datetime format, should be ISO8601...
--The rest should work the same...
UPDATE: Read from a table
Try this:
SELECT t.OtherColumn --add needed columns of your table
,t.YourXmlColumn.value(N'/DADOSNOTAALTA[1]/#titulo',N'nvarchar(max)') AS dadosnota_titulo
,t.YourXmlColumn.value(N'/DADOSNOTAALTA[1]/#mostra',N'int') AS dadosnota_mostra --some int value
--ommited more attributes
,t.YourXmlColumn.value(N'/DADOSNOTAALTA[1]/DTALTA[1]/#titulo',N'nvarchar(max)') AS dtalta_titulo
,t.YourXmlColumn.value(N'/DADOSNOTAALTA[1]/DTALTA[1]/#valor',N'nvarchar(max)') AS dtalta_valor --bad datetime format, should be ISO8601...
--The rest should work the same...
FROM YourTable AS t;

Related

how to update database with extension db1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I am working on updating an outdated database with extension db1, which was created in 2002. But the problem is I can access the structure of this database to create a new one to work with a program that I use it.
DATA BASE Simulatix v1.00 (c)FAROS 1995
¥L<ٍe ض IDENT ب¸ ICAO ±± LATITUDE آ½ًüآ½ً| LONGITUDE آ½ًüآ½ً| ELEV €ےh ¹ MAG VAR €ےh² SPEED LIMIT €ےک´ SPEED LIMIT ALT €ے`¶ TRANS ALT €ے8؛CYFB CY "oEحٹ€إn „‏ PFCYVQ CY 3دtE"ہيإٌ # PFDTMB DT ¼E"R!D
¸EBBR EB Wل>E~‰†C¸ ىےْ '”EDDB ED wkDEïخJD› ْ 'ˆEDDF ED ùں;Eچژ Dlےےْ 'ˆEDDH ED IE3سD5 ْ 'ˆEDDK ED H؟>EGHضC.‎ےْ 'ˆEDDL ED ڑM#Ew·تC“ ِےْ 'ˆEDDM ED ¢S5E’ت0Dخ
ْ 'ˆEDDN ED ³‍9Eي+&D ْ 'ˆEDDP ED ïض#E¼‹7Dر ْ 'ˆEDDS ED H–6EWT
Dَ ْ 'ˆEDDT ED LEEذPGDy ْ 'ˆEDDV ED خ¹DE؛#D· ْ 'ˆEDDW ED پيFEحD üےْ 'ˆEDHI ED قءHE‰ˆD ˆEDLW ED •1AE^نC¨ûےْ 'ˆEDOP ED قYHE ہ0D¦
ْ 'ˆEETN EE حج^Ef>؛D„ ? ˆEFHK EF ‰0bEڑ9»D§ ; ˆEFIV EF 3¥€E«ڑحDل` ˆEFJY EF ح jE¼‹ہDثD ˆEFOU EF |sE«*¾D/ G ˆEFPO EF ïzfE¼{£D, 1 ˆEFRO EF 3›yE3»ءD…N ˆEFTP EF «NfE‰è°D†8 ˆEFTU EF "îbEfِ¦D، 1 ˆEFVA EF wklE3;£D 1 ˆEGBB EG ´³DEjأرآEعے  EGCC EG کHE;أضےْ 'ˆEGGD EG ]¯#E5%#أnطے ¸EGGP EG D HE¼û*أQ شےْ 'ˆEGGW EG ¼‡BEحج°ءâےْ 'pEGHH EG حl>Eڑفآ$ فے  EGJJ EG ،‡8E»أقے ¸EGKK EG "خ?E«ھ6ءؤ كےْ 'pEGLL EG f
AEwwفءP âےْ 'pEGMH EG ‰ˆ#E‰ˆ،B² èے ¸EGNM EG CےIE±Dاآھضے ˆEGNX EG قFEق]ںآ2غےْ ' EGPD EG „VEDأ× خے pEGPF EG …QEق‎„أ اےْ 'pEGPH EG ذQEڑYJأ‡ ثےْ 'pEGPK EG w'PEڑ™‰أA أےْ 'pEGSS EG ڑ‘BEڑ™aA\هےْ 'pEHAM EH ¼'DEحىژCُےٌےْ '¸EHRD EH «ضBEق…Cٌےïےْ '¸EIDW EI {THE-¼أٍ ہے ˆEINN EI و،EELكؤ. °ے ˆEKAH EK SE‏HDR ¸EKBI EK ¶QEشF D÷ ےے ¸EKCH EK 3‘PEïض=D ْ XˆEKKA EK ڈSE’قD« ےے ¸EKRN EK ¼|NE´d]D4 ˆEKSP EK ˆOE~ُ
Dچ ¸EKTS EK VE”D üے ¸EKYT EK VEت¼D
¸ELLX EL R:EH!؛Cزِےْ '”ENAL EN ٍ›jEش–·CE ىے XENAN EN fىپEڑ)rD+ ْ 'XENAT EN …4ƒE`I¯D F ˆENBO EN oB|EڈzWD* XENBR EN بbEçٹœC¥ ىےْ 'XENCN EN ¼CZEحŒٍC9 ِے  ENDU EN حzپEU
‹Dü 2 XENEV EN «j€Eح,zDT ( XENFG EN مخdECRD‰
as you can see I can't open it correctly. Is there any way to open this file .db1 and update it for this year 2022??
I have this program to access DB and check the data as you can see the rows, and column.

SQL Query XML with 'where' clause

I am trying to retrieve a single row of data based on an XML attribute.
The SQL I have so far is:
select C.query('.')
from Bookmarks
cross apply XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
The data returned from this query is (4 rows of data)
<Bookmark Report="DataExplorer" Name="DataExplorer" CustomColumn1="Analysis" CustomColumn2="Data Explorer" Description="Benefit Plan Count" SaveTime="2020-02-21T10:44:36-05:00" BookmarkID="79638e95-c5b7-43f1-b180-f5f31b50dea4" ExtraFile="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="People.ContactInfo.EmergencyContactList" Name="" CustomColumn1="Report" CustomColumn2="Emergency Contact List" Description="Engineering Emergency Contacts" SaveTime="2020-02-21T11:48:28-05:00" BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="22" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="1" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" />
<SessionParameters />
</Bookmark>
<Bookmark Report="TotalRewards.Compensation.SalaryAnalysis" Name="" CustomColumn1="Analysis" CustomColumn2="Salary Analysis" Description="Annual Pay by Employee" SaveTime="2020-02-21T12:03:02-05:00" BookmarkID="30da52af-55d3-4c06-985a-12d428731773" ExtraFile="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="Payroll.PayrollProcessing.PayrollAnalysis" Name="" CustomColumn1="Report" CustomColumn2="Payroll Analysis" Description="Payroll Age 40-49" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397" SaveTime="2020-02-21T12:50:26-05:00" BookmarkID="2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe" ExtraFile="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" rdAgLoadSaved="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml" />
<SessionParameters />
</Bookmark>
but this returns each Bookmark element (4 total). I would like to add a where clause to only return one Bookmark node based on the BookmarkID, but can't seem to figure out how to do this. Is there a way to add something like
where C.query('#BookmarkID') = '953e67ef-d45e-4fac-8d71-b2153a726612'
so that only one Bookmark node is returned?
You could use the value() method to get a single value:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
WHERE c.value('#BookmarkID', 'VARCHAR(36)') = '953e67ef-d45e-4fac-8d71-b2153a726612'
You can also filter directly in the nodes() method:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark[#BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612"]') as T(C);

How to import XML to SQL Server when base nodes repeat

I am importing generated XML files into a SQL Server database. It's been working fine, but now I need additional information from a node that repeats, and I can't figure it out. I am using VBScript with SQLXMLBulkLoad.SQLXMLBulkload.4.0 to import the files. There are many <file> nodes in each file, and here a simplified as an example:
<?xml version="1.0" encoding="UTF-8"?>
<samp_catalog version='1.0'>
<file>
<name>123.wav</name>
<xyz>
<a_samp>
<a_one>1</a_one>
<a_two>2</a_two>
<a_three>3</a_three>
</a_samp>
<b_samp version='2.0'>
<b_four>sample</b_four>
<b_five>sample</b_five>
<b_six>sample</b_six>
</b_samp>
<c_samp version='1.0'>
<c_entry>
<total_size>0</total_size>
<sig>sample</sig>
<type>SAMPLE</type>
<data_size>256</data_size>
<data encoding='string'></data>
</c_entry>
</c_samp>
<c_samp version='1.0'>
<c_entry>
<total_size>0</total_size>
<sig>sample</sig>
<type>PHONE</type>
<data_size>256</data_size>
<data encoding='string'>15555551212</data>
</c_entry>
</c_samp>
<c_samp version='1.0'>
<c_entry>
<total_size>0</total_size>
<sig>sample</sig>
<type>OTHER_SAMPLE</type>
<data_size>256</data_size>
<data encoding='string'></data>
</c_entry>
</c_samp>
</xyz>
</file>
</samp_catalog>
Without the repeating c_samp node, the schema was easy:
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" xmlns:sql = "urn:schemas-microsoft-com:mapping-schema">
<xsd:element name = "samp_catalog" sql:is-constant = "1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name = "file" sql:relation = "files" maxOccurs = "unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name = "name" type = "xsd:string" sql:field = "name" />
<xsd:element name = "xyz" sql:is-constant = "1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name = "a_samp" sql:is-constant = "1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name = "a_one" type = "xsd:integer" sql:field = "a_one" />
<xsd:element name = "a_two" type = "xsd:integer" sql:field = "a_two" />
<xsd:element name = "a_three" type = "xsd:integer" sql:field = "a_three" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name = "b_samp" sql:is-constant = "1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name = "b_four" type = "xsd:string" sql:field = "b_four" />
<xsd:element name = "b_five" type = "xsd:string" sql:field = "b_five" />
<xsd:element name = "b_six" type = "xsd:string" sql:field = "b_six" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
The important one is the second data element (of type PHONE), but importing them all is acceptable as well. I have tried defining all 3 c_samps in the schema and defining a sql:field for only the specified data element and defining it for all elements, however the import always results in NULL for everything under a c_samp element.
How can I get the repeating nodes to import into the database?
I would write a stored procedure in SQL-Server and pass over the XML as-is. Use SQL Server's abilities to read the XML without a schema.
The following code will extract all information from the XML given.
Just do something like
CREATE dbo.ImportMyXML(#xml XML)
AS
BEGIN
--Code here
END
GO
Within the BEGIN END you write this query (out-commented the INSERT INTO to test the query's result:
--INSERT INTO YourTargetTable(col1,col2,col3,...)
SELECT #xml.value(N'(/samp_catalog/file/name/text())[1]',N'nvarchar(max)') AS name
,a_samp.value(N'(*/text())[1]',N'nvarchar(max)') AS a_one
,a_samp.value(N'(*/text())[2]',N'nvarchar(max)') AS a_two
,a_samp.value(N'(*/text())[3]',N'nvarchar(max)') AS a_three
,b_samp.value(N'#version',N'nvarchar(max)') AS b_version
,b_samp.value(N'(*/text())[1]',N'nvarchar(max)') AS b_one
,b_samp.value(N'(*/text())[2]',N'nvarchar(max)') AS b_two
,b_samp.value(N'(*/text())[3]',N'nvarchar(max)') AS b_three
,NodesWith_c_entry.value(N'(../#version)[1]',N'nvarchar(max)') AS c_version
,NodesWith_c_entry.value(N'(total_size/text())[1]','int') AS c_total_size
,NodesWith_c_entry.value(N'(sig/text())[1]','nvarchar(max)') AS c_sig
,NodesWith_c_entry.value(N'(type/text())[1]','nvarchar(max)') AS c_type
,NodesWith_c_entry.value(N'(data_size/text())[1]','int') AS c_data_size
,NodesWith_c_entry.value(N'(data/#encoding)[1]','nvarchar(max)') AS c_data_encoding
,NodesWith_c_entry.value(N'(data/text())[1]','nvarchar(max)') AS c_data_text
FROM #xml.nodes(N'samp_catalog/file/xyz') AS A(xyz)
OUTER APPLY xyz.nodes('a_samp') AS B(a_samp)
OUTER APPLY xyz.nodes('b_samp') AS C(b_samp)
OUTER APPLY xyZ.nodes('*/c_entry') AS D(NodesWith_c_entry);
With the XML given the result is this:
+---------+-------+-------+---------+-----------+--------+--------+---------+-----------+--------------+--------+--------------+-------------+-----------------+-------------+
| name | a_one | a_two | a_three | b_version | b_one | b_two | b_three | c_version | c_total_size | c_sig | c_type | c_data_size | c_data_encoding | c_data_text |
+---------+-------+-------+---------+-----------+--------+--------+---------+-----------+--------------+--------+--------------+-------------+-----------------+-------------+
| 123.wav | 1 | 2 | 3 | 2.0 | sample | sample | sample | 1.0 | 0 | sample | SAMPLE | 256 | string | NULL |
+---------+-------+-------+---------+-----------+--------+--------+---------+-----------+--------------+--------+--------------+-------------+-----------------+-------------+
| 123.wav | 1 | 2 | 3 | 2.0 | sample | sample | sample | 1.0 | 0 | sample | PHONE | 256 | string | 15555551212 |
+---------+-------+-------+---------+-----------+--------+--------+---------+-----------+--------------+--------+--------------+-------------+-----------------+-------------+
| 123.wav | 1 | 2 | 3 | 2.0 | sample | sample | sample | 1.0 | 0 | sample | OTHER_SAMPLE | 256 | string | NULL |
+---------+-------+-------+---------+-----------+--------+--------+---------+-----------+--------------+--------+--------------+-------------+-----------------+-------------+
So far, I haven't found an answer for what I was looking to do, but here is a work around I'm using for now. In VBScript, after loading the file with Microsoft.XMLDOM I loop through the file and find all type nodes whose text value is PHONE and then create a new element and append it to b_samp with its sibling data's text value.
VBScript:
Set nodes = xmlFile.selectNodes("//type")
For Each node in nodes
If node.text = "PHONE" Then
Set phoneNode = xmlFile.CreateElement("phone")
For Each child in node.ParentNode.ChildNodes
If child.nodeName = "data" Then phoneNode.text = child.text
Next
For Each child in node.ParentNode.ParentNode.ParentNode.ChildNodes
If child.nodeName = "b_samp" Then child.appendChild phoneNode
Next
End If
Next
Then save the file with a new name to leave the original intact, and import it with a new schema adding this line right after the b_six element:
<xsd:element name = "phone" type = "xsd:string" sql:field = "phone" />

Changing datasource not working

I have a an Access form with a subform in datasheet mode with edit mode allowed. All tables are stored inside an SQL Server (2008R2) and I just added a new column (bit not null default 0)
The subform datasource span on 3 tables and is working just fine as it is. However, as soon as I add a new column, everytime I try to change data, I get this error :
If I remove the column I just added, everything seems to work again.
Here is the datasource before
SELECT tblCommandeListe.Section, tblCommandeListe.Description, tblCommandeListe.[No item], tblCommandeListe.N°Commande, tblCommandeListe.Code, tblCommandeListe.Qte, tblCommandeListe.Dim, tblFournisseur.[Fournisseur-Nom], tblCommandeListe.Prix, tblCommandeListe.[Date de livraison], tblCommandeListe.[Cost Center], tblCommandeListe.Devise, tblCommandeListe.Complet, tblCommandeListe.[LB/Lin], tblCommandeListe.[Prix/lb], tblCommandeListe.Unite, tblCommandeListe.[Note 2], tblCo mmandeListe.Ordre, tblProduits.[Produit-DescriptionFRA], tblProduits.[Produit-Prix], tblProduits.[Produit-Unite], tblProduits.[Produit-Fournisseur], tblProduits.[Produit-LB/Lin], tblProduits.[Produit-Prix/lb], tblProduits.[Produit-Long nom], tblProduits.[Produit-Devise], tblCommandeListe.Condition, tblCommandeListe.[Date création], tblCommandeListe.[Enlever liste à commander], tblCommandeListe.[Unite ing], tblProduits.[Produit-Unite_ing], tblCommandeListe.[Dim ing], tblCommandeListe.DescTmp, tblCommandeListe.[User mod], tblCommandeListe.[Qte req], tblCommandeListe.Annuler, IIf(IsNull([Qte req]),0,[Qte req])*IIf(IsNull([Prix]),0,[Prix])*IIf(IsNull([Dim]),1,[Dim])*IIf(IsNull([LB/Lin]) Or [LB/Lin]=0,1,[LB/Lin]) AS Total, tblCommandeListe.[Relaché pour achat], tblProduits.[Produit-Priorité], tblFournisseur.[Fournisseur-Nom]
FROM (tblCommandeListe
LEFT JOIN tblProduits ON tblCommandeListe.Code = tblProduits.[Produit- Code])
LEFT JOIN tblFournisseur ON tblProduits.[Produit-Fournisseur] = tblFournisseur.Fournisseur_id
ORDER BY tblCommandeListe.Section, tblCommandeListe.Description;
and after I add the column
SELECT tblCommandeListe.Section, tblCommandeListe.Description, tblCommandeListe.[No item], tblCommandeListe.N°Commande, tblCommandeListe.Code, tblCommandeListe.Qte, tblCommandeListe.Dim, tblFournisseur.[Fournisseur-Nom], tblCommandeListe.Prix, tblCommandeListe.[Date de livraison], tblCommandeListe.[Cost Center], tblCommandeListe.Devise, tblCommandeListe.Complet, tblCommandeListe.[LB/Lin], tblCommandeListe.[Prix/lb], tblCommandeListe.Unite, tblCommandeListe.[Note 2], tblCommandeListe.Ordre, tblProduits.[Produit-DescriptionFRA], tblProduits.[Produit-Prix], tblProduits.[Produit-Unite], tblProduits.[Produit-Fournisseur], tblProduits.[Produit-LB/Lin], tblProduits.[Produit-Prix/lb], tblProduits.[Produit-Long nom], tblProduits.[Produit-Devise], tblCommandeListe.Condition, tblCommandeListe.[Date création], tblCommandeListe.[Enlever liste à commander], tblCommandeListe.[Unite ing], tblProduits.[Produit-Unite_ing], tblCommandeListe.[Dim ing], tblCommandeListe.DescTmp, tblCommandeListe.[User mod], tblCommandeListe.[Qte req], tblCommandeListe.Annuler, IIf(IsNull([Qte req]),0,[Qte req])*IIf(IsNull([Prix]),0,[Prix])*IIf(IsNull([Dim]),1,[Dim])*IIf(IsNull([LB/Lin]) Or [LB/Lin]=0,1,[LB/Lin]) AS Total, tblCommandeListe.[Relaché pour achat], tblProduits.[Produit-Priorité], tblFournisseur.[Fournisseur-Nom], tblCommandeListe.EstProduction
FROM (tblCommandeListe
LEFT JOIN tblProduits ON tblCommandeListe.Code = tblProduits.[Produit- Code])
LEFT JOIN tblFournisseur ON tblProduits.[Produit-Fournisseur] = tblFournisseur.Fournisseur_id
ORDER BY tblCommandeListe.Section, tblCommandeListe.Description;
The only difference I see is the new column at the end. I tried with other columns and so far, it still works after, so the problem might be the column itself, but how can that be ?
EDIT : I just did a test and it seems I get the exact same message when I tried to edit it directly in the table in Access!

How i get the similarity of phrases in C# .NET

I have a sql database with data about headers of news. Example:
id title
867 MPE consegue inverter julgamento
868 Defensoria P blica realiza licita
869 Prefeitos eleitos de todas as partes do Estado
870 Inc ndio deixa 80 pessoas desabrigadas
871 Carlos Amastha visita parlamentares
872 Defensoria P blica requer anula o
873 Marcelo Miranda diz que n o possui obriga o
874 Ex-assessor diz que Coimbra lhe deu dois cheques
I need to get each title and see if there are other news to talk about the same subject.
How i do it? My plataform is .Net and use sql server 2012.
You will probably want to put a Full-Text Index on this column and/or table. It's a complex subject, but you can start reading up on it here: http://msdn.microsoft.com/en-us/library/ms142571.aspx

Resources