Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
William Fields asked whether global variables can be set from a dynamic SQL statement in Server Studio; SET and LET gave syntax errors. Alexandre Marini said globals are only available in SPL. Art Kagel asked for the real problem. William found a stored procedure that sets the variable and called it with execute procedure. Solved.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
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.
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.
Your privacy choices
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.