# Convert float to bool SQL historian

**URL:** <https://forum.inductiveautomation.com/t/convert-float-to-bool-sql-historian/32326>\
**Category:** Ignition\
**Created:** [February 17, 2020, 3:40am UTC](https://forum.inductiveautomation.com/t/convert-float-to-bool-sql-historian/32326 "2020-02-17T03:40:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [February 17, 2020, 3:40am UTC](https://forum.inductiveautomation.com/t/convert-float-to-bool-sql-historian/32326/1 "2020-02-17T03:40:59Z")

</div>

Ignition 8.0  
SQL server express

Hi.

Due to hardware restrictions, I’m forced to read data from 2 digital proximity switches as analog values (0…1000mV). \<~50mV is 0, \>~900mV is 1.  
I would like to log this data to our SQL database using historian. However I’m wondering what the most elegant solution is to achieve this. Ideally, I would like to avoid having a second set of tags (if possible).

Accquire data, threshold logic, log to MSSQL.

I’m currently logging the data as the analog value but this seems wasteful. I’d like to log this as a boolean on change of value.

Suggestions? Any help would be great.

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 17, 2020, 12:15pm UTC](https://forum.inductiveautomation.com/t/convert-float-to-bool-sql-historian/32326/2 "2020-02-17T12:15:24Z")

</div>

By “threshold logic” I presume you mean hysteresis? That requires prior state when evaluating new samples. I’m biased towards the [objectScript()](https://www.automation-pros.com/simaids/doc/expression.objectscript.html) expression function from my [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) module for such cases, using its state variable to hold prior output. Something like this:

```auto
objectScript("someModule.thresholdFunction(binding.state, args[0])", {[.]AnalogTag})

```

with a threshold function like this:

```auto
def thresholdFunction(state, milliVolts):
    if 'prior' in state:
        if state['prior']:
            result = milliVolts > 50
        else:
            result = milliVolts > 900
    else:
        result = milliVolts > 475
    state['prior'] = result
    return result

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 17, 2020, 12:44pm UTC](https://forum.inductiveautomation.com/t/convert-float-to-bool-sql-historian/32326/3 "2020-02-17T12:44:47Z")

</div>

I may be missing something here, but unless it’s the slowest transistor ever, do you ever see any intermediate values?

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [February 17, 2020, 3:05pm UTC](https://forum.inductiveautomation.com/t/convert-float-to-bool-sql-historian/32326/4 "2020-02-17T15:05:56Z")

</div>

why not use an expression tag? I know you said you dont want a 2nd set of tags but I cant imagine any other solution being more simple.

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [February 19, 2020, 8:57am UTC](https://forum.inductiveautomation.com/t/convert-float-to-bool-sql-historian/32326/5 "2020-02-19T08:57:08Z")

</div>

Thanks Guys

I think I’ll use a couple of expression tags.
