Questions tagged [user-variables]

SQL variables set by the user, without special significance to the RDBMS.

Often referring to SQL server variables, these are variables created by the user, as opposed to system variables presented by the underlying platform.

59 questions
10
votes
8 answers

JMeter - Can I combine 2 user variables into one?

I was wondering if you are able to combine two user variables into one. For example I have one user variable which is defined as the location of a root folder, and a second variable defined as a location from the root, down into a subfolder, and…
James King
  • 2,425
  • 7
  • 30
  • 45
6
votes
1 answer

Guarantees when using user variables to number rows

Using user variables to number rows I often find answers here on SO suggesting the use of user variables to number some thing or other. Perhaps the clearest example would be a query to select every second row from a given result set. (This question…
MvG
  • 57,380
  • 22
  • 148
  • 276
3
votes
2 answers

user variables in mysql update statement

Let t be a mysql table and n be an integer column in it. I would be interested if the following query can be modified so that the expression n - 10 is calculated only once. UPDATE t SET n = if(n - 10 < 1, 1, n - 10) WHERE n = 5; The query does not…
clime
  • 8,695
  • 10
  • 61
  • 82
3
votes
1 answer

SSIS Package with User Variable in Where Clause

Simply put, I'm trying to take user input, store it in a variable, and then use that variable in a query. First, I have a Script Task that opens a window with a simple input text box and a button. On click, the text gets put into a user variable and…
Mark Griggs
  • 317
  • 1
  • 3
  • 13
3
votes
1 answer

Is there a way to use a user-defined variable as a column length in a CREATE TABLE statement?

test.sql: SET @my_var = 50; CREATE TABLE test_table ( id SMALLINT NOT NULL, my_text VARCHAR(@my_var), PRIMARY KEY (id) ); Command line interaction: mysql> source d:/test.sql; Query OK, 0 rows affected (0.00 sec) ERROR 1064 (42000):…
Hammerite
  • 21,755
  • 6
  • 70
  • 91
3
votes
2 answers

MySQL increment user variable when value changes

I have a table consisting of groups of, for example, five rows each. Each row in each group possesses a date value unique to that group. What I want to do in my query, is go through the table, and increment a user variable (@count) when this date…
Fela Maslen
  • 2,022
  • 3
  • 25
  • 46
2
votes
1 answer

Defining user variables in stored procedures / routines for MySQL 9.0

According to the MySQL 8.0 deprecations notes, starting MySQL 9.0 the definition of user variables with DECLARE (e.g. DECLARE studentID INT) will be deprecated: Support for setting user variables in statements other than SET was deprecated in MySQL…
Mike
  • 14,010
  • 29
  • 101
  • 161
2
votes
3 answers

Perform UPDATE and setting a user variable in one single query

Everyone familiar with php's mysql_query command, knows that it doesn't allow us to perform more than one query (separated by the ; delimiter) in one call... My problem is that I wan't to be able to define a user variable in my UPDATE query so that…
artikboy
2
votes
1 answer

SSIS 2012 - Load xml files from folder into a SQL Server table COLUMN, using Execute SQL Task and ForEachLoop Container

Today I have a new situation, in which out client asks the following: We have XML files in a folder. We need to load these files into a SQL Server table column (which has XML data type); we are NOT loading the XML outputs into various SQL Server…
user3812887
  • 439
  • 12
  • 33
2
votes
3 answers

MySQL Stored Procedure with Insert Select and user variable

Problem: I have a MySQL stored procedure and I want to reset a user variable to 0 each time the procedure is called, but the variable seems to be remembering its value from each previous run and I cannot initialize it to zero. Details: I have a data…
Dan
  • 59,490
  • 13
  • 101
  • 110
1
vote
2 answers

Path missing in User Variables

Deleted Path in User Variables for Pc1, what can I do? and I keep getting [error 2147942402 (0x80070002) when launching `ubuntu2204.exe'] when opening terminal app, I also copied values of Path in System Variables to new Path variable in User…
1
vote
1 answer

How do I get a MySQL/MariaDB user defined variable working in grafana?

Using MariaDB 5.5 (our asterisk cdr database) and trying to build a time series by date out of existing data in the database, but want to join to a column of all dates in order to account for days that have no data. The following query (simplified)…
1
vote
2 answers

Odd behavior of user-defined variables in MySQL

I've noticed something odd about user-defined variables: Lets say I have this table: num_table +---------+ | numbers | | 3 | | 6 | | 9 | +---------+ I can create a comma-separated list and store it in a user-defined variable like…
jisaacstone
  • 4,234
  • 2
  • 25
  • 39
1
vote
1 answer

simulate row_number with variables ignore order

I was trying to help with this question Selecting rows based on a few rules The idea is for each user select the row id with the language matching @lenguage otherwise select the first language created. Because doesn't have row_number(), had to use…
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
1
vote
1 answer

MySQL 8 - user variables within expressions is deprecated (complex calculation)

// EDIT // Below is the original question, but my problem can be really simplified with one question... how can I get the below output without using user variables?! SELECT ID, @cumu_return:=IF(id = 1, 1, @cumu_return + (@cumu_return * ret)) AS…
Shahid Thaika
  • 2,133
  • 5
  • 23
  • 59
1
2 3 4