Error in statement time > X

  • Hi, i need help please,

    Why this not work:

    SELECT change_dtim,create_dtim,ckpt_id,Format([change_dtim]-[create_dtim],'hh:nn:ss') as tempo FROM Back_ickpt_plz where tempo > '00:15:00'

    if i remove the where tempo > '00:15:00' , run .

    What is my mistake?

    Thks a lot,

    Regards,

    Cachado

  • jcachado (1/23/2016)


    Hi, i need help please,

    Why this not work:

    SELECT change_dtim,create_dtim,ckpt_id,Format([change_dtim]-[create_dtim],'hh:nn:ss') as tempo FROM Back_ickpt_plz where tempo > '00:15:00'

    if i remove the where tempo > '00:15:00' , run .

    What is my mistake?

    Thks a lot,

    Regards,

    Cachado

    Quick suggestion

    😎

    SELECT change_dtim,create_dtim,ckpt_id,[change_dtim]-[create_dtim] FROM Back_ickpt_plz where change_dtim > CONVERT(TIME,'00:15:00',0)

  • But i need bigger than 15 minutes!

    The statement is ok but the condition > '00:15:00' dont work.

    🙁

    Thks,

    Cachado

  • It won't run, because you're referencing an alias in the WHERE clause. Aliases only get assigned at a point after the WHERE has run.

    You could do

    SELECT change_dtim,create_dtim,ckpt_id,Format([change_dtim]-[create_dtim],'hh:nn:ss') as tempo FROM Back_ickpt_plz where Format([change_dtim]-[create_dtim],'hh:nn:ss') > '00:15:00'

    It should work, won't be very efficient. To suggest a more efficient form, we're going to need to see the data types and sample data for the table.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • jcachado (1/23/2016)


    But i need bigger than 15 minutes!

    The statement is ok but the condition > '00:15:00' dont work.

    🙁

    Thks,

    Cachado

    You have 15 minutes passed midnight in your query, if you need anything different then you must ask for that otherwise you will not get what you need.

    😎

  • Please see the file:

    https://www.dropbox.com/s/3ok41iuqg9pqd2p/1.png?dl=0

    i need only the records in expression > 15 minutes

    🙁

    Regards,

    Cachado

  • Eirikur Eiriksson (1/23/2016)


    jcachado (1/23/2016)


    But i need bigger than 15 minutes!

    The statement is ok but the condition > '00:15:00' dont work.

    🙁

    Thks,

    Cachado

    You have 15 minutes passed midnight in your query, if you need anything different then you must ask for that otherwise you will not get what you need.

    😎

    But the field have the difference in minutes between the change_dtim field and the field create_dtim!!

  • GilaMonster (1/23/2016)


    It won't run, because you're referencing an alias in the WHERE clause. Aliases only get assigned at a point after the WHERE has run.

    You could do

    SELECT change_dtim,create_dtim,ckpt_id,Format([change_dtim]-[create_dtim],'hh:nn:ss') as tempo FROM Back_ickpt_plz where Format([change_dtim]-[create_dtim],'hh:nn:ss') > '00:15:00'

    It should work, won't be very efficient. To suggest a more efficient form, we're going to need to see the data types and sample data for the table.

    Thks its work but change the &gt with >

    Regards,

    Cachado

  • Strongly advice you not to use the format function as it performs very badly.

    😎

  • Eirikur Eiriksson (1/23/2016)


    Strongly advice you not to use the format function as it performs very badly.

    😎

    What your sugestion to replacing format command?

    Thks,

    JC

  • jcachado (1/23/2016)


    Eirikur Eiriksson (1/23/2016)


    Strongly advice you not to use the format function as it performs very badly.

    😎

    What your sugestion to replacing format command?

    Thks,

    JC

    Like Gail said, we need to see the DDL for the table to be able to suggest an efficient approach. See the link in my signature for descriptions of DDL, sample data and expected output. This sounds pretty simple, but without knowing the table you're querying, there's really no way to offer any suggestions.

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply