Does HUE support dynamic sql queries?

Hello,

I’m attempting a dynamic SQL query where I loop through all the tables in my database, extracting the first row in each table:

DECLARE @tableName NVARCHAR(MAX), @sql NVARCHAR(MAX)

DECLARE tableCursor CURSOR FOR
    SELECT name FROM information_schema.tables
    
OPEN tableCursor

FETCH NEXT FROM tableCursor INTO @tableName

WHILE @@FETCH_STATUS = 0
BEGIN
    SET @sql = 'SELECT TOP 1 * FROM ' + @tableName
    EXEC sp_executesql @sql
    FETCH NEXT FROM tableCursor INTO @tableName
END

CLOSE tableCursor
DEALLOCATE tableCursor

however, I get the error

Error while compiling statement: FAILED: ParseException line 1:0 cannot recognize input near 'DECLARE' 'tableName' 'NVARCHAR'

Is there something wrong with my query, or does HUE not support dynamic queries?