Friday, August 24, 2018

AX - How get active country code

This country code is readed from legal entity. The example shows how to work with macro. #isoCZ is in #ISOCountryRegionCodes macro defined as "CZ".
#ISOCountryRegionCodes
static void Job(Args _args)
{
  LogisticsAddressCountryRegionISOCode isoCode = SysCountryRegionCode::countryInfo();
    
  if (isoCode == #isoCZ ) info( isoCode );
}
Output:
CZ
Note: To defined macro you can pass parameters. In macro you access to its by order -> %1, %2 ...and so on.

Monday, August 6, 2018

SQL SERVER - How to interpret empty string as NULL value

When is in varchar field saved NULL value, is situation easy:
select isnull( revision, '< null >' ) from drawing_drawing;
Output is:
----------
< null >
Different situation is when varchar field is only empty. In that case isnull() returns only empty string:
select isnull( revision, '< null >' ) from drawing_drawing;
Output is:
----------
The solution is to use inner function nullif() - ...question: which value is NULL ?
select isnull( nullif( revision, '' ), '< null >' ) from drawing_drawing;
Output is:
----------
< null >

Thursday, August 2, 2018

ORACLE - How declare variable accross existing table field (%type)

Both variables are declared accross existing PEOPLE.NAME table field:
function Month_Execute( pPeriod varchar2, sErrorMessage out varchar2 ) return number
is
  sMinName people.name%type;
  sMaxName people.name%type;
begin
...

SQL SERVER - How disable updating of the table/field, UPDATE trigger

This code disable updating of the table:
create trigger [dbo].[drawing_drawing_update]
on [dbo].[drawing_drawing]
for update
as
begin
  set nocount on;

  raiserror( N'Table can`t be updated.', 16, 1 ) with nowait;
  rollback tran;
  return;
end;
Alternatively, you can protect only specified updated field(s):
create trigger [dbo].[drawing_drawing_update]
on [dbo].[drawing_drawing]
for update
as
begin
  set nocount on;

  if UPDATE( validsince )
  begin
    raiserror( N'Field can`t be updated.', 16, 1 ) with nowait;
    rollback tran;
    return;
  end;
end;
When you trying to save row in application, this message will appears: