Home > Uncategorized > #Base64 decode using #SQL server #UDF

#Base64 decode using #SQL server #UDF


Base64 is a way to encode data into a limited character set, that can allow binary data to be displayed using print-friendly text. For example, if you wanted to represent an image as text, and store it in a database. It does bloat data, but it’s certainly handy when it comes to passing data around.

SQL server doesn’t have a handy function to convert base64 text back into it’s original form, so I decided to write this UDF below;

CREATE FUNCTION dbo.Base64Decode (@Base64 varchar(max))
RETURNS varchar(max)
DECLARE @TEXT AS varchar(max) ;
@TEXT = CAST( CAST( @Base64 as XML ).value(‘.’,’varbinary(max)’) AS varchar(max) );


Categories: Uncategorized
  1. Adrián Fernández Martín
    May 26, 2019 at 6:33 pm

    Hey, you can see more base64 c# examples at this website https://tobase64.dev

  1. No trackbacks yet.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: