MOVE

Function

Moves one field to another field and optionally edits the field.

Syntax

MOVE {src_any_lit|_var|_col} TO dst_any_var
[[:$]format_mask|NUMBER|MONEY|DATE]

Arguments

src_any_lit|_var|_col

Specifies any source column, variable, or literal.

Note:

A date can be stored in a date variable or column, or a string literal, column, or variable. When using a date format_mask or the keyword DATE with MOVE, the source, if a string literal, column, or variable, must be in the format specified by SQR_DB_DATE_FORMAT, one of the database-dependent formats in Table 61, Default Formats by Database, or the database-independent format 'SYYYYMMDD[HH24[MI[SS[NNNNNN]]]]'.

When numerical precision is important, use LET. When no edit mask is specified, MOVE uses the 6 digit precision default mask.

dst_any_var

A destination variable.

format_mask

Optional format mask. (see Edit Masks)

NUMBER

Formats src_any_lit|_var|_col with the NUMBER‑EDIT-MASK from the current locale. Not legal with date variables. (see Edit Masks)

MONEY

Formats src_any_lit|_var|_col with the MONEY‑EDIT-MASK from the current locale. Not legal with date variables. (see Edit Masks)

DATE

Formats src_any_lit|_var|_col with the DATE‑EDIT‑MASK from the current locale. Not legal with numeric variables. (see Edit Masks)

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:

Finally, as this example shows, the edit mask can be contained in a string variable.

Examples

This example illustrates the various features of MOVE:

The following code:

!
! 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

The following code:

!
! 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

The following code:

!
! 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

The following code:

!
! Convert a number to a string using the default edit mask
!
! Production Reporting, by default, ouputs 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

The following code:

!
! 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

The following code:

!
! 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

The following code:

!
! 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-1999

The following code:

!
! 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 1995.

$Date2 = 10/01/95 00:00

The following code:

!
! 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-1995

The following code:

!
! Convert string (in partial format of SYYYYMMDDHHMISSNNN) to a
! date
! 
move '19951129' to $date1
show '$Date1 = ' $date1 edit 'Mon DD YYYY HH:MI'

Produces the following output.

$Date1 = Nov 29 1995 00:00

See Also