Writing a String based upon the value of an integer?

What I’m attempting to do is have ignition log a string based upon what value an integer is.

Say for Example I move a one into the integer FaultStatusCode, I want to log the string “Motor Current Low” into the SQL table instead of a one. If I move a two into FaultStatusCode, I want to log the string “Motor Current High” into the SQL table.

Here’s some pseudocode to help explain what I’m wanting to do:

[code]READ FaultStatusCode

IF FaultStatusCode=1 THEN
WRITE “Motor Current Low”
IF FaultStatusCode=2 THEN
WRITE “Motor Current High”

I’m going to have more than three options, but this should suffice to get the concept across. I’ve got a long way to go with ignition, but if I can handle this with the SCADA it will save me time associating strings with a status indicator in the PLC.

Okay, I think I might have figured it out. So what you need to do is create a new expression item in your desired transaction group. Once you’re there you need to write a switch statement in the “Expression/SQL” tab.

The code will have the following structure:

switch ({[~]TAG_LOCATION}, 1,2,3, "Message #1", "Message #2", "Message #3")

If there’s a better way to do it, feel free to chime in.

You can just create a table in sql that maps the fault code to the message.

FaultCodeID, Message
1, Motor Current Low
2, Motor Current High
3, Motor Speed Low
4,Motor Speed High

You can keep writing the actual fault code into the database.
Later on when querying the tables you can join on this faultcode table to display the actual message.

Another option, along the same lines as jpark’s suggestion:

Create a Memory tag, datatype of Dataset, and then populate it with your fault codes. Then, if you need to reference the integer status code, but make it human readable, you can just do an Expression binding like this:
{FaultCodes}[{Root Container.Spinner.intValue},0]
The first {} contains the tagpath of the Memory Tag with your fault codes listed.
The square brackets [] identify which row and column of the dataset to return.
The second {} contains a simple property on a component in the window - you could use anything to control this.

This expression function would return whatever row of the dataset is indicated by the Spinner component. Note that this is zero-indexed; the square bracket [Row, Column] reference starts at 0,0 as the first element in the dataset.