AnsweredAssumed Answered

Inserting Digital State Codes

Question asked by chantry on Oct 31, 2016
Latest reply on Nov 2, 2016 by pthivierge

For my current application, I am inserting datapoints that may or may not be digital state codes in PI. Preferably, I would like to be able to treat digital state codes as integers and insert just like any normal integer. For example, I'd like to be able to do insert(tag, time, value) values ('tag-name', '*', 1).


However, when this query is run on a digital state type tag, the error "[PIOLEDB] Row insertion failed. Digital state code couldn't be converted to a digital state." is generated.


As a work around, I can format my query like the following


insert picomp2 (tag, time, value)
select 'tag-name', '*', code
     select top 1 * from pipoint2 where tag = 'tag-name'
) as point
join pids on pids.digitalset = point.digitalset
where pids.offset = 1


This seems like overkill for something that should be simple. It also cannot be used for normal queries, so I would need to know ahead of time that my datapoint is a digital state code. I have no representation of the digital codes outside of PI, so the DIGCODE() function is not a possible solution for me.


Is there not a better method to do this that I'm not seeing in the documentation?