# How to use a OPC value to

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529>\
**Category:** Ignition\
**Created:** [August 7, 2023, 4:50pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529 "2023-08-07T16:50:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Joshua\_Hoekstra](https://forum.inductiveautomation.com/u/Joshua_Hoekstra)\
**Post date:** [August 7, 2023, 4:50pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/1 "2023-08-07T16:50:57Z")

</div>

I am trying to refence a tag in my queries but I keep getting weird errors. Any help would be appericated  
SELECT Built  
FROM View\_ActiveOrders  
Where Targetlineid = 50 And Orderid ='[DT Right Hand]New Tag'  
One of the errors  
Conversion failed when converting the varchar value '[DT Right Hand]New Tag' to data type int.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 7, 2023, 4:57pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/2 "2023-08-07T16:57:50Z")

</div>

> [@Joshua\_Hoekstra](#):
>
> Orderid ='[DT Right Hand]New Tag'

That's a string and the data column appears (from the error) to be defined as an INT.

If this is in a script then please post some context so we know where `[DT Right Hand]New Tag` is supposed to be coming from.

Tip: Please format code in your posts.

 ![Formatting code](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/0/70741738ea3cbbe8a2d249e1194c80035567335c.png)

---

<div class="post-metadata">

**Author:** ![Joshua\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Joshua\_Hoekstra](https://forum.inductiveautomation.com/u/Joshua_Hoekstra)\
**Post date:** [August 7, 2023, 5:08pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/3 "2023-08-07T17:08:43Z")

</div>

I was using that in the Named Queries

---

<div class="post-metadata">

**Author:** ![Joshua\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Joshua\_Hoekstra](https://forum.inductiveautomation.com/u/Joshua_Hoekstra)\
**Post date:** [August 7, 2023, 5:10pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/4 "2023-08-07T17:10:03Z")

</div>

The Tag I am using is a refence tag which is set up as an int

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 7, 2023, 5:10pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/5 "2023-08-07T17:10:37Z")

</div>

> [@Joshua\_Hoekstra](#):
>
> I was using that in the Named Queries

Please show us how. Make it easy for us to help you. Provide details as requested.

---

<div class="post-metadata">

**Author:** ![Joshua\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Joshua\_Hoekstra](https://forum.inductiveautomation.com/u/Joshua_Hoekstra)\
**Post date:** [August 7, 2023, 5:17pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/6 "2023-08-07T17:17:59Z")

</div>

```auto
SELECT Built
FROM View_ActiveOrders 
Where Targetlineid = 50 And Orderid = '[DT Right Hand]New Tag.value' 

```

---

<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:** [August 7, 2023, 5:19pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/7 "2023-08-07T17:19:09Z")

</div>

First, there's no way for SQL to tell that your string constant is supposed to be a tag. You need to use a value parameter. Then where you **call** the named query, you retrieve and supply the tag **value** to the parameter.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 7, 2023, 5:21pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/8 "2023-08-07T17:21:45Z")

</div>

That's not how this works.

You need to pass the tag's value to the the named query where you're calling it.  
Use a parameter in your named query (it looks like this `:parameter`).

> **[Using Named Queries in Perspective Video at Inductive University](https://inductiveuniversity.com/videos/using-named-queries-in-perspective/8.1)**
>
> In this lesson we'll take some of the the Named Queries created in the previous topic, and call them with Perspective components.

[https://docs.inductiveautomation.com/display/DOC81/Named+Queries](https://docs.inductiveautomation.com/display/DOC81/Named+Queries)

---

<div class="post-metadata">

**Author:** ![Joshua\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Joshua\_Hoekstra](https://forum.inductiveautomation.com/u/Joshua_Hoekstra)\
**Post date:** [August 7, 2023, 5:26pm UTC](https://forum.inductiveautomation.com/t/how-to-use-a-opc-value-to/77529/9 "2023-08-07T17:26:47Z")

</div>

I will give this a try thank you
