Exploring SQL server 2016 T-SQL functions- DECOMPRESS

In the earlier post on  Exploring SQL server 2016 T-SQL functions- COMPRESS we have learnt how to compress the values using COMPRESS function. In this post we will learn how to use DECOMPRESS function to get the original value from the compressed value

Let us create this compressed dataset

 create table #test_compress(data varbinary(max))
 insert into #test_compress(data)
 select compress('test') as compressed_Data

When you select data from this table,

 select data from #test_compress

you get the following result

data
------------------------------------------------------
0x1F8B08000000000004002B492D2E01000C7E7FD804000000

To get the original value, you can use DECOMPRESS function

select
    cast(decompress(data) as varchar(max)) as data
from
    #test_compress

The result is

data
---------------
test

Note : The decompressed data should be converted to varchar datatype to see the value in original format

Other posts on new features of SQL Server 2016
Exploring SQL Server 2016 T-SQL functions – STRING_SPLIT
SQL Server 2016 – Drop If Exists
Exploring SQL server 2016 T-SQL functions- COMPRESS

Advertisements

One thought on “Exploring SQL server 2016 T-SQL functions- DECOMPRESS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s