Questions tagged [variable]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers

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 ...
jprealini's user avatar
  • 101
-1 votes
2 answers

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: ...
Lexen's user avatar
  • 3
1 vote
1 answer

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 ...
Mark Freeman's user avatar
  • 2,171
0 votes
1 answer

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 = ''--...
guradio's user avatar
  • 97
0 votes
1 answer

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, @...
hellyeah99's user avatar
0 votes
0 answers

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 "...
AleksTr's user avatar
0 votes
1 answer

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 ...
Hugo Delsing's user avatar
0 votes
0 answers

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 ...
lifeisajourney's user avatar
0 votes
0 answers

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 ...
Thomas Lauria's user avatar
1 vote
1 answer

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 ...
Edgar Magallon's user avatar
0 votes
1 answer

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; ...
HeyJude's user avatar
  • 447