PyCharm's database console does not “remember” previously declared variables

Answered
Suppose I want to execute the following SQL statements in PyCharm's database console:
DECLARE @today DATETIME = GETDATE()
SELECT @today

When I execute the two statements in one go (selecting both of them, then hitting ctrl+Enter), it works as expected.

But if I execute the first statement, and then the second one separately, I get the error Must declare the scalar variable "@today".

Is there a way to make the console keep variables in scope for more than one statement?

0
1 comment

It's expected behavior. AFAIK, SSMS works in the same way. You need to execute all statements at once.

0

Please sign in to leave a comment.