Compare Sqltimestamp type field

Asked

Viewed 199 times

1

I have a question here... I have a field in the SQL Server database of the type Datetime that can be null. In Delphi, within the Memtable (or Clientdataset... would be the same thing in my case), the field was created as Sqltimestamp Field. I want to see if this field has a date or is null, but I didn’t get a correct comparison without giving compilation error saying that the types are different. Follows the code:

if fDm.fdmEmail.FieldByName('esr_ultimo').AsSQLTimeStamp > 0 then // Aqui dá erro na compilação
begin
  // Formatar o campo...
  edtUltimo.Text := SQLTimeStampToStr('dd/mm/yyyy', fDm.fdmEmail.FieldByName('esr_ultimo').AsSQLTimeStamp);
end;

I’ve tried "<> NULL", "<> 'NULL'", and several others... Thanks in advance.

  • 2

    Try to use the .AsDateTime instead of .AsSQLTimeStamp, and tell if the result was positive.

  • Victor, it worked. When formatting the date for the Edit field I also used "Asdatetime" and the "Formatdatetime" function to format it correctly. Thank you!

  • Could turn comment into reply?

  • Sorry, I’m new around here... how do I do it?

  • I’m not sure how either. but I believe that I have this option, take a look: http://meta.pt.stackoverflow.com/questions/2333/por-que-muitas-peoples-respond-nos-coment%C3%A1rios-em-vez-de-criar-uma-resposta/2334#2334

  • For mi nothing appears that allows me to do this. I think I need to have more scores so I can turn comments into answers...

Show 1 more comment

2 answers

1


Try to use the .AsDateTime instead of .AsSQLTimeStamp, and tell if the result was positive.

  • 1

    The citation highlight does not apply to this case. You don’t need to apply citation highlight to a reply just because it was a comment turned back.

  • Great, thanks for the info.

0

You can use the Isnull property, it would look like this:

fDm.fdmEmail.FieldByName('esr_ultimo').IsNull;

This property returns true/false.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.