<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Server Base64 Convert - MSSQL Query</title>
	<atom:link href="https://mssqlquery.com/tag/sql-server-base64-convert/feed" rel="self" type="application/rss+xml" />
	<link>https://mssqlquery.com</link>
	<description>MSSQL and TSQL Programming and TSQL Examples</description>
	<lastBuildDate>Thu, 05 May 2022 13:46:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.2</generator>

<image>
	<url>https://mssqlquery.com/wp-content/uploads/2023/06/cropped-mssql-query-icon-32x32.png</url>
	<title>SQL Server Base64 Convert - MSSQL Query</title>
	<link>https://mssqlquery.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Function that Encodes Text to Base64 in SQL Server</title>
		<link>https://mssqlquery.com/function-that-encodes-text-to-base64-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Thu, 05 May 2022 13:46:03 +0000</pubDate>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Base64 in SQL Server]]></category>
		<category><![CDATA[Encodes Text to Base64 in SQL Server]]></category>
		<category><![CDATA[SQL Server Base64 Convert]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=950</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about the function that encodes text to Base64 in SQL Server. In SQL Server, in some cases, you may want to encode text to Base64. You can easily do this using the code below. CREATE FUNCTION [dbo].[fnBase64Encode] (&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/function-that-encodes-text-to-base64-in-sql-server">Function that Encodes Text to Base64 in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about the function that encodes text to Base64 in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to encode text to Base64.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">CREATE FUNCTION [dbo].[fnBase64Encode]
(
    @plain_text VARCHAR(6000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
    --local variables
    DECLARE @output VARCHAR(8000),
            @input_length INTEGER,
            @block_start INTEGER,
            @partial_block_start INTEGER, -- position of last 0, 1 or 2 characters
            @partial_block_length INTEGER,
            @block_val INTEGER,
            @map CHAR(64);
    SET @map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
    --initialise variables
    SET @output = '';
    --set length and count
    SET @input_length = LEN(@plain_text + '#') - 1;
    SET @partial_block_length = @input_length % 3;
    SET @partial_block_start = @input_length - @partial_block_length;
    SET @block_start = 1;
    --for each block
    WHILE @block_start &lt; @partial_block_start
    BEGIN
        SET @block_val = CAST(SUBSTRING(@plain_text, @block_start, 3) AS BINARY(3));
        --encode the 3 character block and add to the output
        SET @output
            = @output + SUBSTRING(@map, @block_val / 262144 + 1, 1) + SUBSTRING(@map, (@block_val / 4096 &amp; 63) + 1, 1)
              + SUBSTRING(@map, (@block_val / 64 &amp; 63) + 1, 1) + SUBSTRING(@map, (@block_val &amp; 63) + 1, 1);
        --increment the counter
        SET @block_start = @block_start + 3;
    END;
    IF @partial_block_length &gt; 0
    BEGIN
        SET @block_val
            = CAST(SUBSTRING(@plain_text, @block_start, @partial_block_length)
                   + REPLICATE(CHAR(0), 3 - @partial_block_length) AS BINARY(3));
        SET @output
            = @output + SUBSTRING(@map, @block_val / 262144 + 1, 1) + SUBSTRING(@map, (@block_val / 4096 &amp; 63) + 1, 1)
              + CASE
                    WHEN @partial_block_length &lt; 2 THEN
                        REPLACE(SUBSTRING(@map, (@block_val / 64 &amp; 63) + 1, 1), 'A', '=')
                    ELSE
                        SUBSTRING(@map, (@block_val / 64 &amp; 63) + 1, 1)
                END + CASE
                          WHEN @partial_block_length &lt; 3 THEN
                              REPLACE(SUBSTRING(@map, (@block_val &amp; 63) + 1, 1), 'A', '=')
                          ELSE
                              SUBSTRING(@map, (@block_val &amp; 63) + 1, 1)
                      END;
    END;
    --return the result
    RETURN @output;
END;


---Kullanımı
 
SELECT dbo.fnBase64Encode('Yavuz Selim Kart') AS Base64</code></pre>
<p>When you run the above code, you will see a result similar to the one below.</p>
<p><img decoding="async" fetchpriority="high" class="alignnone wp-image-953 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/05/function-that-encodes-text-to-base64-in-sql-server-1.jpg" alt="Function that Encodes Text to Base64 in SQL Server" width="700" height="455" srcset="https://mssqlquery.com/wp-content/uploads/2022/05/function-that-encodes-text-to-base64-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/05/function-that-encodes-text-to-base64-in-sql-server-1-300x195.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have encoded the text to Base64.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 200</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/function-that-encodes-text-to-base64-in-sql-server">Function that Encodes Text to Base64 in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
