SET GLOBAL Variable in SQL Select?
Posted in 2019
Topics: Stored Procedures & SPL
Hello, All of the examples I can find show how to set a global variable inside SPL functions. Can values be assigned to global variables from within a dynamic SQL statement? I'm using Server Studio and have tried SET/LET but all I get is syntax errors. Thanks.
Hi. According to the official docs, global variables are only available for SPL code. https://www.ibm.com/support/knowledgecenter/en/SSGU8G_12.1.0/com.ibm.sqlt.doc/id s_sqt_450.htm HTH Best regards Alexandre Marini
What is it that you are trying to accomplish by using a global variable William? Post the problem, not the solution that doesn't work! Problems we can solve.
Sorry for the delay in responding. Here is some background. There is a view in one of our databases that filters records based on the value of a GLOBAL variable. I thought I needed a way to set that variable via a SQL statement. As it turns out, there is a stored procedure in the database just for that purpose. So, by calling that stored procedure with an "execute procedure" call (using SQL), I was able to achieve the desired results. Thank you.