Share via


Unzip a file in TSQL from a variable

Question

Wednesday, December 21, 2011 10:26 AM | 1 vote

Hi,

I have a SQL Table with a VARBINARY column that holds XML files that have been zipped.

I need to unzip these files and read the contents in order to perform some logic. I am restricted to SQL and so this will need to be done in TSQL. Note that this is a read only operation and I will not need to save anything back.

I am able to read the contents of an unzipped XML file and perform the required logic, All that is left to do, is to perform the unzip functionality. As these files are relatively small, I would prefer to do it in memory from a variable and not to save the file back to the file system just to unzip it.

I am using SQL 2008 R2.

Can this be done, or is there another / better approach?

I appreciate your comments and suggestions.

Kind regards

Lourens

All replies (4)

Wednesday, December 21, 2011 12:11 PM ✅Answered | 1 vote

also T-sql script to unzip file http://www.sqlservercentral.com/Forums/Topic960855-392-1.aspx
http://uk.linkedin.com/in/ramjaddu


Wednesday, December 21, 2011 10:54 AM | 1 vote

You can ZIP and UNZIP files using xp_CMDSHELL. Ofcourse, it will create the UNZIP files on file system. You have to use winzip command line utility.

For example, check here;

http://p2p.wrox.com/sql-language/28071-unzip-stored-procedure.html

 

 

  

Please visit my Blog for some easy and often used t-sql scripts
My BizCard


Wednesday, December 21, 2011 11:00 AM

i believe you will at least need CLR integration to do the unzip part.


Monday, December 26, 2011 6:36 PM

RamJaddu,

Fix your hyperlink pls. Thanks.

Kalman Toth, SQL Server & Business Intelligence Training; SQL SERVER GRAND SLAM