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
1
vote
1 answer

Select row where row number is equal to some value from other table

I have two tables: game and tasks Game looks like this: | step | manualTaskCounter | autoTaskCounter | (and other) ---------------------------------------------------------- | 1 | 3 | 1 |…
Kalreg
  • 982
  • 1
  • 13
  • 27
1
vote
1 answer

mysql: set column to value from previous row based on another column's value

Trying to do the following: if current row's column c1 is equal to previous row's c1, set column c3 to previous row's column c2; otherwise, set c3 to NULL (or just don't set it to anything). Can someone tell me why the following query results in c3…
Yury
  • 722
  • 7
  • 14
1
vote
2 answers

Querying a table for an uservariable list

I have the following Problem: I have a table table1 with multiple columns col1 through col2: +------+------+ | col1 | col2 | +------+------+ | 1 | 4 | | 2 | 4 | | 3 | 4 | | 4 | 5 | +------+------+ Now I need…
Max Belli
  • 167
  • 2
  • 7
1
vote
2 answers

How to get a list of suburbs surrounding a location then repeat for other locations using MySql?

I get a list of suburbs within a specified distance from a single location using Queries A. I’m trying to adapt Queries A to get a list of suburbs surrounding location1, then get list of suburbs surrounding location2 and so on (I'll call this…
TryHarder
  • 2,704
  • 8
  • 47
  • 65
1
vote
1 answer

mysql update statement behaves differently based on whether a user variable exists

I'm reseting a sort column that has duplicate or missing values like so: set @last=''; set @sort=NULL; update conf_profile set sort= if( @last=(@last:=concat(org_id,',',profile_type_id,',',page,',',col)), (@sort:=@sort+1), …
ysth
  • 96,171
  • 6
  • 121
  • 214
1
vote
1 answer

Reset/clear MySQL user variables

I have bunch of MySQL queries that use temporary tables to split complex/expensive queries into small pieces. create temporary table product_stats ( product_id int ,count_vendors int ,count_categories int ,... ); -- Populate…
mr.Kame
  • 153
  • 3
  • 12
1
vote
1 answer

MySQL: change user variable for each selected row

I'm trying to select the first ten empty time slots between appointments in a MySQL database. The appointment table has basically 3 fields: appointment_id INT, startDateTime DATETIME and endDateTime DATETIME. We can imagine some data like this (for…
ixM
  • 1,244
  • 14
  • 29
1
vote
2 answers

Can we access user variable in query of Source in DFT?

I am working on optimizing a Data Flow Task. I Ado.Net source firing a query like below. Select Emp_id, EmpName, Salary from Employee. After source I hace a derived column transform whcih adds a derived column with user variable value…
Pritesh
  • 1,938
  • 7
  • 32
  • 46
0
votes
1 answer

User variable not incrementing

Why would the following query not increment seq? SELECT @sq :=if(@previous=uid,@sq,0)+1 as seq ,@previous:=uid as user FROM test Result: seq user 1 111 1 111 1 111 1 222 1 222 1 222
Mahks
  • 6,441
  • 6
  • 28
  • 31
0
votes
1 answer

Multiple mysql statements on same connection

I'm building a search query and was wondering if the code below would be valid. Basically I would set the @keywords variable in the first statement and then use it in the 2nd statement. It seems to be working just fine but I'm not sure if it's a…
Alex
  • 1
0
votes
1 answer

SSIS Updating User Variables from a CSV file

I am fairly new to SSIS and I have been looking everywhere for the answer to this question and can't find it, which makes me think its really simple and obvious, because I'm pretty sure this is a standard problem with SSIS. I am building a SSIS…
JYatesDBA
  • 25
  • 1
  • 10
0
votes
0 answers

How do I pass a user variable (@variable) as a column name in a select statement?

Here is my table: enter image description here My statement is returning this: enter image description here But I want it to return this: enter image description here enter image description here
Steve
  • 1
0
votes
1 answer

Variables in mysql initialized with string datatype

In Mysql, user variables are taking string values when declared inside select statement. I have a table named 'a' with one column named 'amount' as shown…
0
votes
0 answers

get updated rows' id in mysql with user variable

I have a statement like this and it works fine, but there is a warning: update addresses_not_synced SET lock_until =DATE_ADD(now(), interval 60 second) where (lock_until < now() or lock_until is null) and (SELECT…
Hamid Naghipour
  • 3,465
  • 2
  • 26
  • 55
0
votes
1 answer

User-defined variables support in Sqlalchemy

Does SQLAlchemy have support for user-defined variables? https://dev.mysql.com/doc/refman/5.6/en/user-variables.html Problem: I am trying to get the time difference between two consecutive rows. I can do this by writing raw SQL query using…
Lemon Reddy
  • 553
  • 3
  • 5