Book a Demo

Author Topic: Convert to float in sql query  (Read 7535 times)

amacara1

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Convert to float in sql query
« on: February 08, 2023, 02:10:12 am »
I am using Version field of EA elements as float numbers. Is there a way to convert the field during an sql query so that I can compare like Version < 1.2 ?
Thank you!

BobM

  • EA User
  • **
  • Posts: 144
  • Karma: +9/-0
    • View Profile
Re: Convert to float in sql query
« Reply #1 on: February 08, 2023, 02:23:35 am »
Quote
WHERE
(LEFT(VERSION,1) < 1 OR
LEFT(VERSION,1) = 1 AND RIGHT(VERSION,1) < 1)

It will automatically convert to numeric

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Convert to float in sql query
« Reply #2 on: February 08, 2023, 03:24:29 am »
There are also conversion functions to a decimal.
Their syntax depends on the database you are using.

Geert

amacara1

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Convert to float in sql query
« Reply #3 on: February 08, 2023, 03:31:44 am »
Quote
WHERE
(LEFT(VERSION,1) < 1 OR
LEFT(VERSION,1) = 1 AND RIGHT(VERSION,1) < 1)

It will automatically convert to numeric

This does help, but I will sooner-rather-than-later reach version 10.10. Then what do I do?

amacara1

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Convert to float in sql query
« Reply #4 on: February 08, 2023, 03:32:33 am »
There are also conversion functions to a decimal.
Their syntax depends on the database you are using.

Geert
I was hoping there is a thing similar to #thing# :( We are using jet 4 (eapx) and Mysql.

amacara1

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Convert to float in sql query
« Reply #5 on: February 08, 2023, 03:40:31 am »
val() seems to work at my side.

BobM

  • EA User
  • **
  • Posts: 144
  • Karma: +9/-0
    • View Profile
Re: Convert to float in sql query
« Reply #6 on: February 09, 2023, 01:15:25 am »
Quote
WHERE
(LEFT(VERSION,1) < 1 OR
LEFT(VERSION,1) = 1 AND RIGHT(VERSION,1) < 1)

It will automatically convert to numeric

This does help, but I will sooner-rather-than-later reach version 10.10. Then what do I do?

My apologies I was lazy
REVERSE is not that performant, there might be better solutions but below is a five second tought fix for every single above 9 number

Code: [Select]
WHERE
(LEFT(VERSION,CHARINDEX('.',VERSION)-1) < 1 OR
LEFT(VERSION,CHARINDEX('.',VERSION)-1) = 1 AND RIGHT(VERSION,CHARINDEX('.',REVERSE(VERSION))-1) < 1)
« Last Edit: February 09, 2023, 01:21:08 am by BobM »

amacara1

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Convert to float in sql query
« Reply #7 on: February 09, 2023, 03:07:26 am »
Thank you, BobM for your time. Pittyfully, CHARINDEX did not work on my jet 4 :(
But, I solved my need with val(), which is ok for now.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Convert to float in sql query
« Reply #8 on: February 09, 2023, 08:57:52 am »
Thank you, BobM for your time. Pittyfully, CHARINDEX did not work on my jet 4 :(
But, I solved my need with val(), which is ok for now.
For MS Access you need INSTR()  (The CHARINDEX equivalent)'

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!