Monday, March 25, 2019

SQL SERVER - How to get end of month date

select eomonth( getdate(), -1 )
select eomonth( getdate() )    
select eomonth( getdate(), 1 )
Output:
----------
2019-02-28

(1 row(s) affected)


----------
2019-03-31

(1 row(s) affected)


----------
2019-04-30

(1 row(s) affected)

Tuesday, March 19, 2019

DELPHI - How to go through all rows in dataset with bookmark

Bookmarks store your position in dataset and  after action you can return back to original record.
var
  iCount : integer;
  pBookmark : TBookmark;
  pDataSetSource : TDataSet;
begin
  ...
  Screen.Cursor := crHourGlass;
  iCount := 1;
  pBookmark := pDatasetSource.GetBookmark;
  pDatasetSource.DisableControls;
  try

    pDatasetSource.First;
    while not pDatasetSource.Eof do
      begin
        try

          { action with record }

        finally
          inc( iCount );
          pDatasetSource.Next;
        end;

      end;
  finally
    pDatasetSource.GotoBookmark( pBookmark );
    pDatasetSource.EnableControls;

    Screen.Cursor := crDefault;
  end;

DELPHI - How to show enum name as string (TFieldType)

Add System.TypInfo to your uses statement:
var
  i : integer;
  pColumn : TcxGridDBColumn;
begin
  ...
  for i := 0 to pGridView.VisibleColumnCount - 1 do
    begin
      pColumn := TcxGridDBColumn( pGridView.VisibleColumns[i] );

      ShowMessage( pColumn.DataBinding.FieldName + ' , ' + 
                   GetEnumName( TypeInfo(TFieldType), 
                                ord( pColumn.DataBinding.Field.DataType ) ) );
    end;
  ...
Output:

Thursday, March 7, 2019