Comment
New Contributor III

Thanks for posting this, it's quite useful!

I am having trouble using the INTO command to assign the result of the query into a variable. This is only happening on SQL Serverless, while using all-purpose compute (DBR 14.3 LTS) works.

Code sample:

DECLARE OR REPLACE sum INT;
DECLARE OR REPLACE sqlStr = 'SELECT 10';
EXECUTE IMMEDIATE sqlStr INTO sum;
SELECT sum;

 Running this on all-purpose compute I get the correct output of 10:

iamgoda_0-1719602229185.png

Running it on SQL Serverless, the value of sum is null: 

iamgoda_1-1719602345251.png

This was run on a SQL notebook, but same issue happens when running in SQL Editor:

iamgoda_2-1719602538338.png

Any idea why this is happening?

Thanks!