MOVE
Syntax
MOVE {src_any_lit|_var|_col} TO dst_any_var [[:$]format_mask|NUMBER|MONEY|DATE]
Description
Moves the source field to the destination field. Optionally, you can reformat the field using the format_mask argument. Source and destination fields can be different types: numeric, text, or date. MOVE is also useful for converting from one type to another; however, date and numeric variables are incompatible.
When a date variable or column is moved to a string variable, the date is converted according to the following rules:
-
For DATETIME columns and SQR DATE variables, SQR uses the format specified by the SQR_DB_DATE_FORMAT setting.
If this has not been set, SQR uses the first database-dependent format as listed in the Default Database Formats table.
-
For DATE columns, SQR uses the format specified by the SQR_DB_DATE_ONLY_FORMAT setting.
If this has not been set, SQR uses the format listed in the DATE Column Formats table.
-
For TIME columns, SQR uses the format specified by the SQR_DB_TIME_ONLY_FORMAT setting.
If this has not been set, SQR uses the format as listed in the TIME Column Formats table.
Finally, as the example shows, the edit mask can be contained in a string variable.
Parameters
| Parameter | Description |
|---|---|
|
src_any_lit | _var | _col |
Specifies any source column, variable, or literal. Note that a date can be stored in a date variable or column, or a string literal, column, or variable. When you are using a date format_mask or the keyword DATE with the MOVE command, the source, if a string literal, column, or variable, must be in the format specified by the SQR_DB_DATE_FORMAT setting, one of the database-dependent formats as listed in the Default Database Formats table, or the database-independent format 'SYYYYMMDD[HH24[MI[SS[NNNNNN]]]]'. |
|
dst_any_var |
Specifies a destination variable. |
|
format_mask |
Specifies an optional format mask. For additional information regarding edit masks, see the PRINT command. |
|
NUMBER |
Indicates that src_any_lit|_var|_col is to be formatted using the NUMBER-EDIT-MASK from the current locale. This option is not allowed with date variables. (See the ALTER_LOCALE command.) |
|
MONEY |
Indicates that src_any_lit|_var|_col is to be formatted using the MONEY-EDIT-MASK from the current locale. This option is not allowed with date variables. (See the ALTER_LOCALE command.) |
|
DATE |
Indicates that src_any_lit|_var|_col is to be formatted using the DATE-EDIT-MASK from the current locale. This option is not allowed with numeric variables. (See the ALTER_LOCALE command.) |
Example
The following example illustrates the various features of the MOVE command:
!
! Convert a string in place
!
move '123456789' to $ssn
move $ssn to $ssn xxx-xx-xxxx
show '$SSN = ' $ssn
Produces the following output:
$SSN = 123-45-6789
!
! Convert a number to a string using an edit mask
!
move 1234567.89 to #value
move #value to $value 999,999,999.99
show '$Value = ' $value
Produces the following output:
$Value = 1,234,567.89
!
! Convert a number to a string using a variable edit mask
!
move 123 to #counter
move '099999' to $mask
move #counter to $counter :$mask
show '$Counter = ' $counter
Produces the following output:
$Counter = 000123
!
! Convert a number to a string using the default edit mask
!
! SQR, by default, outputs six digits of precision.
! If you require more or less precision, specify an edit mask.
!
move 123.78 to #defvar
move #defvar to $defvar
show '$DefVar = ' $defvar
Produces the following output:
$DefVar = 123.780000
!
! Convert the number to a string using the locale default
! numeric edit mask
!
alter-locale number-edit-mask = '99,999,999.99'
move 123456.78 to #nvar
move #nvar to $nvar number
show '$NVar = ' $nvar
Produces the following output:
$NVar = 123,456.78
!
! Convert the money value to a string using the locale default
! money edit mask
!
alter-locale money-edit-mask = '$9,999,999.99'
move 123456.78 to #mvar
move #mvar to $mvar money
show '$MVar = ' $mvar
Produces the following output:
$MVar = $ 123,456.78
!
! Convert the date column to a string using the locale default
! date edit mask
!
begin-select
dcol
from tables
end-select
alter-locale date-edit-mask = 'Mon-DD-YYYY'
move &dcol to $dvar date
show '$DVar = ' $dvar
Produces the following output:
$DVar = Jan-01-2004
!
! Reset date to first day of the month
! ($date1 and $date2 have been defined as date variables)
!
let $date1 = datenow()
move $date1 to $date2 'MMYYYY'
show '$Date2 = ' $date2 edit 'MM/DD/YY HH:MI'
Produces the following output if the report was run in October of 2004:
$Date2 = 10/01/04 00:00
!
! Convert date to a string
! ($date1 has been defined as a date variable)
!
move $date1 to $str_date 'DD-MON-YYYY'
show '$Str_Date = ' $str_date
Produces the following output:
$Str_Date = 01-DEC-2004
!
! Convert string (in partial format of SYYYYMMDDHHMISSNNN) to a
! date
!
move '20041129' to $date1
show '$Date1 = ' $date1 edit 'Mon DD YYYY HH:MI'
Produces the following output:
$Date1 = Nov 29 2004 00:00
See The LET command for information
about copying, editing, or converting fields
See The EDIT parameter of the
PRINT command for a description of the edit masks
See The ALTER-LOCALE command
for a description of the arguments NUMBER-EDIT-MASK, MONEY-EDIT-MASK,
and DATE-EDIT-MASK
See The PRINT command regarding
the default date-time components as a result of moving an incomplete
date to a date variable