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

#Base64 decode using #SQL server #UDF

base64-logo-352x200

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)
WITH SCHEMABINDING AS
BEGIN
DECLARE @TEXT AS varchar(max) ;
SELECT
@TEXT = CAST( CAST( @Base64 as XML ).value(‘.’,’varbinary(max)’) AS varchar(max) );

RETURN @TEXT ;
END;
GO

Advertisement
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

    Like

  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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: