Replace data from XML file after it is moved in SQL Server database - sql-server

I am developing an upload system when a user uploads XML files, then certain data from that XML file will copied into a SQL Server database.
My question is: can we copy a tag name (ABC_1234_1_121) and change its format into something like this ([1234] 1 ABC 121) and save that into the table in the database? Is it possible doing this? I need anyone help on this.
This is the example of XML files which will be uploaded into the server.
<ABC_1234_1_121>
<OTHER_TAGS>
..
</OTHER_TAGS>
</ABC_1234_1_121>
As you can see, the (ABC_1234_1_121) is from the <tag> of file xml above. I wanted to change the format to [1234] 1 ABC 121 when I extract the tag to SQL Server database. But I do not know if this is possible to be done.

Related

How to migrate SQL Server Image datatype to Azure blob container?

We are migrating our data from on-premise to the cloud. One requirement is to store the attachments (.pdf, .txt, .png etc) data from a SQL Server table in Azure blob containers in a particular format.
The table structure looks like this:
TABLE
(
Id int,
Name nvarchar,
EntityId int,
RecordId int,
BlobData image
)
The files should be saved in following way in the container.
Folder structure : Container//Entity ID//Record ID//Files
For example:
BlobContainer//10//1//xyz.pdf, png.png
Here I consider both files xyz and abc to belong to same entity (10) and record (1).
I tried Azure Data Factory, but I am unable to find a proper solution as I am facing a source sink mismatch issue when trying to use "Copy Data" activity in a pipeline.
Has anyone faced the same problem or do you have any other solution to complete this task?

Is it possible to push XML file(Load the Data) to SQL Server via SSIS (Visual Studio) without XSD file?

Question 1: is it possible to push only XML file to SQL Server via SSIS (Visual Studio) without XSD file?
Question 2: is it possible to push only XML file to SQL Server without XSD?
If yes, how can we process it, and any guidance or link would be helpful.
If no, what would be the reason, Why we cannot push the XML file to DB without XSD?
I surfed the net more than 6 hours, I couldn't find any solution.
In SQL Server you can convert a text representing XML as you please, like:
CONVERT(XML, N'somexml', 2)
In the code above replace somexml with your XML. The docs provide a nice example about how you can specify XML as a type of a column:
CREATE TABLE T (XmlColumn xml default N'<element1/><element2/>');
Before you continue reading, try experimenting by the creation of the table above and inserting XML into it, as:
insert into T(xml)
values(N'<element1/><element2/>');
Now, if your tests confirm that you are able to convert a text into XML in the way shown above, then the only thing remaining is to convert whatever XML you have in your application code into a text. I do not know what your application code/framework is, but this is how you can do it with C#:
https://forums.asp.net/t/1630414.aspx?How+to+convert+XML+to+Text+file+using+C+

Upload/update xml files on SQL Server

I have some .xml files in a local folder (for example, C:\xml). I also have a table in SQL Server with columns Name (varchar) and XMLContent (xml).
How can I upload all my files from local folder to SQL Server, compare them and update in case they are different or insert a new entry containing filename without .xml and xml content if file is absent on server?
Is it solvable? Maybe there are a ready solution for this action? I'm not very good at SQL.
Looks like I've found the perfect solution. It does exactly what I wanted.
Upload multiple XML files

Bulk Insert csv file from FTP server with T-SQL

Basically what the title is saying.
Today when I use bulk insert with T-SQL on Microsoft SQL Server 2008 to get data from a local drive I use the following query,
BULK INSERT tmp_table
FROM 'c:\data\x.csv'
WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '0x0a' );
Which works ok. But now I want to be able to read .csv data files from a folder on a FTP server.
As every other FTP server, I need username\password to log in first, and then, I somehow need to fetch the files. Is this possible with T-SQL?
I do know that with C# this would be a piece of cake for me, but want to learn this by using T-SQL.
I will also need to know how I can dynamically get the names of files from a given folder on the FTP server, but since I'm taking this one step at a time, you don't need to answer this right away.
When the files are on local drive i am able to use xp_dirtree to get the names of all files in a folder.
An excellent guide can be found here http://www.patrickkeisler.com/2012/11/how-to-use-xpdirtree-to-list-all-files.html

How to save the generated XML file in a directory passing him in sql server?

Personally I'm with a doubt saving my XML in sql server. I am using FOR XML PATH to generate the xml from a table in my database. The sql server shows me on the screen the XML generated but not saved to file it (well, I guess not lol). How do I save it by passing a directory?
I have the following query to generate XML:
select TableName,
operation,
UserName,
DataAcesso,
CamposTabela,
ValoresCampos,
CamposPKs,
ValoresCamposPKs
FROM TabelaLog
FOR XML PATH ('Log')
anyone know how to save to file?
thank you!
You can try the BCP utiity
bcp "select TableName, operation, UserName, DataAcesso, CamposTabela, ValoresCampos, CamposPKs, ValoresCamposPKs FROM TabelaLog FOR XML PATH ('Log')" queryout "D:\MyTable.csv" -c -t , -S SERVERNAME -T
However, the headers must be passed explicitly, if you want them. You can use a UNION ALL for that purpose.
Check out this post. Has some good instructions on exporting info from a query\table to file
How do I send a database query to a text file?
Alternatively you could use SQL Server Integration services (SSIS) and setup a scheduled job to export the information periodically. That would be my option. Another alternative would be to pull it into your application and then save\export it from server side code rather than letting the database do it for you.

Resources