# Change Part Number through Scripting

**URL:** <https://forum.inductiveautomation.com/t/change-part-number-through-scripting/9339>\
**Category:** Ignition\
**Created:** [November 13, 2014, 9:49pm UTC](https://forum.inductiveautomation.com/t/change-part-number-through-scripting/9339 "2014-11-13T21:49:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pknox](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pknox](https://forum.inductiveautomation.com/u/pknox)\
**Post date:** [November 13, 2014, 9:49pm UTC](https://forum.inductiveautomation.com/t/change-part-number-through-scripting/9339/1 "2014-11-13T21:49:42Z")

</div>

We are trying to take the Product Number displayed in the label below and if it has “S8” in the product number, we want the “S8” to be replaced with “SS” through the scripting. We are doing a query and scripting on the same label.  
Does anybody have any insight as to how to take the Product Number and replace the “S8” with “SS”? Do I need a new label where the query is separate from the scripting? I have tried this and still can not get it to work. Thanks in advance.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6f1f50de615c6f51c164c3ad9f61250d18819448.JPG)

---

<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:** [November 13, 2014, 11:08pm UTC](https://forum.inductiveautomation.com/t/change-part-number-through-scripting/9339/2 "2014-11-13T23:08:46Z")

</div>

The issue is that the query overwrites what the script is doing. Instead of a script, try using a replace() function in your query:

`SELECT DISTINCT CASE WHEN PART_CODE = '{Root Container.PART_NUMBER.text}' 
THEN REPLACE(CUST_PART,'S8','SS')
ELSE REPLACE('{Root Container.PART_NUMBER.text}','S8','SS')
FROM cust_part `

---

<div class="post-metadata">

**Author:** ![pknox](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@pknox](https://forum.inductiveautomation.com/u/pknox)\
**Post date:** [November 14, 2014, 12:44pm UTC](https://forum.inductiveautomation.com/t/change-part-number-through-scripting/9339/3 "2014-11-14T12:44:13Z")

</div>

Thanks, Jordan. This worked out just like I was hoping. Appreciate the feedback. I added END after the ELSE REPLACE statement.

`SELECT DISTINCT CASE WHEN PART_CODE = '{Root Container.PART_NUMBER.text}' 
THEN REPLACE(CUST_PART,'S8','SS')
ELSE REPLACE('{Root Container.PART_NUMBER.text}','S8','SS')
END
FROM cust_part`

---

<div class="post-metadata">

**Author:** ![SeanT](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@SeanT](https://forum.inductiveautomation.com/u/SeanT)\
**Post date:** [November 18, 2014, 8:04pm UTC](https://forum.inductiveautomation.com/t/change-part-number-through-scripting/9339/4 "2014-11-18T20:04:28Z")

</div>

You may want to check the execution plan of your query - depending on your database, without a WHERE clause it could be scanning the whole table and returning the `'{Root Container.PART_NUMBER.text}'` that you plug into the ELSE piece of your case statement once for each row, then filtering out the repeats. Could end up being a big performance issue if your table was very large.
