Questions tagged [variable]
The variable tag has no usage guidance.
12 questions
0
votes
1
answer
25
views
How to define variable in dynamic SQL in IBM Db2?
In Db2 v11.5 on Linux I would like to create variable and then use this variable in SELECT statement. I don't want to create procedure or function on database, I just want to do this in dynamic SQL ...
0
votes
0
answers
276
views
Dynamically selecting a table in a query based on result from joined SELECT
I have seen many examples but they don't match with my special case (I know... everyone's case is a special case :D )
I have to match values from different tables, some of which are named after the id ...
-1
votes
2
answers
5k
views
PostgreSQL: Issue Declaring Variables in Query
I'm trying to declare a variable for later use in a PostgreSQL query. I've done this often in TSQL, but I wasn't sure about the syntax.
The stuff I've seen online all points to something like this:
...
1
vote
1
answer
78
views
What is the optimal way to handle literals that are referenced in NOT IN clauses of many queries within a Stored Procedure?
Back in the days of C (before C#) and in environments where memory was very limited or expensive (or both), there was a benefit to reducing repetitive use of a literal as it would reduce memory usage ...
0
votes
1
answer
23
views
comparing a variable in when oracle sql
I want to use a variable in when clause of oracle sql like below
DEFINE balancing_id = 0--'16493'--null;
ON A.BALANCING_ID =
CASE
WHEN &balancing_id is null-- &balancing_id = ''--...
0
votes
1
answer
60
views
execute insert and select statements consecutively after a case statement
I want to execute insert and select statements once a condition is met on mysql, not sure how to do it.
##declare variables
SET @fvar = 'sometxt', @svar = 'sometxtagain';
SELECT @start := 1, @...
0
votes
0
answers
173
views
How to use variable in the select query PostgreSQL
I'm looking for a way to write a recursive query, but I'm getting an error.
"SQL Error [42601]: ERROR: syntax error at or near "with recursive"
Position: 287"
query result "...
0
votes
1
answer
75
views
Average Density & cardinality estimation
In a large web application we had a query that was running slow in code, that seemed to be working blazing fast in SSMS. After checking the basics like the same SET options, we found that there was ...
0
votes
0
answers
23
views
Local variables and their impact on execution plans in SQL Server Stored Procedure [duplicate]
If a parameter that is passed to stored procedure is assigned to a local variable and the local variable is used inside the stored procedure logic, will that affect the execution plan in any way? Is ...
0
votes
0
answers
686
views
MySQL IF NULL of a variable is not working as expected in a trigger
We have the following trigger to ensure that a version field is updated in a related table, normally the trigger contains only the UPDATE statement, the INSERTs are added for debugging and to explain ...
1
vote
1
answer
969
views
Is it safe to use user defined variables inside stored procedures in MySQL?
Currently I'm working with Stored Procedures in MySQL and I'm using in some procedures user-defined variables and I've seen that type of variables are initialized in the current session and keep their ...
0
votes
1
answer
366
views
Count how many variables equal a target value
Is there a smart way to count how many variables equal some target value (in SQL Server)?
For example, if I have:
declare @a int = 1;
declare @b int = 2;
declare @c int = 1;
declare @target int = 1;
...