Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Cannot get a T-SQL Function (mysql routine) to work?

Featured Replies

Hi everyone,

After having success with my first T-SQL function, I've made it so that I can url-decode data when pulling it from the database without having to it manually - great!

 

However, I'm not having the same sort of luck with trying to base64-decode the data via a T-SQL Function. I've tried various functions found on google, however they're all kicking up errors when I try to import it using phpMyAdmin

Code is below:

CREATE FUNCTION FromBase64 (@data varchar(max))

RETURNS varchar(8000)

AS

BEGIN

DECLARE

@Output varchar(8000),

@Bits varbinary(3)

— declare vars.

DECLARE @XmlData xml

— construct an xml var.

SET @XmlData = CAST(‘<data>’ + @data + ‘</data>’ as xml)

— base64 decode the @data.

SELECT @Output= CONVERT(varchar(max),

@XmlData.value(‘(data)[1]’, ‘varbinary(max)’))

RETURN @Output

END

The phpMyAdmin error I am getting is:

Static analysis:

2 errors were found during analysis.

    Unexpected character. (near "[" at position 380)
    Unexpected character. (near "]" at position 382)

SQL query: Documentation

CREATE FUNCTION FromBase64 (@data varchar(max) CHARSET utf8) RETURNS varchar(8000) BEGIN DECLARE @Output varchar(8000), @Bits varbinary(3) — declare vars. DECLARE @XmlData xml — construct an xml var. SET @XmlData = CAST(‘<data>’ + @data + ‘</data>’ as xml) — base64 decode the @data. SELECT @Output= CONVERT(varchar(max), @XmlData.value(‘(data)[1]’, ‘varbinary(max)’)) RETURN @Output END

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@data varchar(max) CHARSET utf8)

RETURNS varchar(8000)

BEGIN

DECLARE

' at line 1

I've tried messing about changing the code around to look moire like the my previous function is structured, however nothing is working, and I have tried several of these scripts from google with no success from any!?

Can someone shed some light for me please? I'm new to T-SQL so I've not really got a clue!

Thanks



Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.