Upload/update xml files on SQL Server - 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

Related

How to generate Insert statement from PGAdmin4 Tool?

We are writing a new application, and while testing, we will need a bunch of dummy data. I've added that data by using MS Access to dump excel files into the relevant tables into the Postgres database.
What should I do now to generate an Insert statements from the PGAdmin4 Tool similar to what SQL Studio allow us to generate an Insert statements for SQL Server? There are no options available to me. I can't use the closest one, which is to export and import the data via CSV.
I understand that you cannot import the CSV file into the actual DB as this needs to be done through ASP.NET core EF. Perhaps, you can probably create a test schema and import the CSV file into the test schema. Once you have the data imported into the test schema, you can use that to generate SQL statements using the steps below:
Right click on target table and select "Backup".
Select a file path to store the backup. You can save the file name as data.backup
Choose "Plain" as Format.
Open the tab "Options" check "Use Column Inserts".
Click the Backup-button.
Once the file gets generated you can open with Notepad++ or VSCode to get the SQL insert statements
You can use the statements generated and delete the test schema created
Here is a resource that might help you in loading data from Excel file into PostgresSQL if you still need to take this path Transfer Data from Excel to PostgreSQL

How to load data from UNIX to snowflake

I have created CSV files into UNIX server using Informatica resides in. I want to load those CSV files directly from UNIX box to snowflake using snowsql, can someone help me how to do that?
Log into SnowSQL:
https://docs.snowflake.com/en/user-guide/getting-started-tutorial-log-in.html
Create a Database, Table and Virtual Warehouse, if not done so already:
https://docs.snowflake.com/en/user-guide/getting-started-tutorial-create-objects.html
Stage the CSV files, using PUT:
https://docs.snowflake.com/en/user-guide/getting-started-tutorial-stage-data-files.html
Copy the files into the target table using COPY INTO:
https://docs.snowflake.com/en/user-guide/getting-started-tutorial-copy-into.html

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

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.

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 execute folder with SQL Server 2008 scripts

I have a folder with a .sql files; 1 file per query. I want to execute all queries/ sql files and save them as csv.
Is there a way to do that automated without using the windows cli (disabled in my environment). I do have the SQL Server Management Studio.
I would approach this task using SSIS, providing you have Business Intelligence Development Studio (BIDS) installed.
First create a 'Foreach Loop Container' pointed to the folder with the SQL files, then use a variable to retreive each file name.
Next, create a flat file connection and set the 'Connection String' property to the variable that contains the file location.
Next, using the 'Execute SQL Task' component set the 'SQLSourceType' to 'File Connection' and the 'FileConnection' to the one created in the previous step.
Finally, depending on how the data is returned you have a couple of options, if the result set is small, only a row or a single column, then you can save the results to a variable and using a 'Dataflow' task create a 'Derived Column' component and export the contents of that variable to a CSV file. Or, if the dataset is larger you could dump the results to a temp table and then using an 'OLE DB Source' and 'OLE DB Destination' you could push the full result set straight into a CSV.
Hopefully this isn't too convoluted of a solution, this approach has the advantage of being able be run from either a remote machine or from the server itself, plus you can automate its execution with a SQL Agent Job.
Create a VB.NET console application.
Generate a list of files that end in .SQL from the folder in question.
Load the contents of each file into individual SQL Commands
Execute the SQL Command for each, storing the results in DataSets.
For each table in each dataset, create a new .csv file
For each .csv file, you will need to iterate over each cell in the datatable, and utilize proper escaping for .csv files.
Use 'for' in combination with either sqlcmd or bcp command for each file in the script folder.

Resources