Published on InterSystems Developer Community (https://community.intersystems.com)

Home > How can I add two values in a segment field separated by ~

Question
ED Coder · Apr 30, 2021

How can I add two values in a segment field separated by ~

I am updating the PV1 segment with values from the database but when I get two values back I dont know how to separate them with a tilde and insert. Any advice for me on that?

so if I get two values returned

 

my PV1.7 segment should be :  

My current code is as below: It works fine for one value, but when there are more than 2 values returned I need to find a way to include it

Set res=##class(%ResultSet).%New("%DynamicQueryGW:SQLGW")

Set sc=res.Prepare(sqlstring,,conn)

Set sc=res.Execute()

while res.Next()
    {
     s RET = res.GetData(2)
}
    
    s sc=res.Close()
    
    Set sc=conn.Disconnect()

//Modify the segment   
//create a copy of the request
s newREQ = pRequest.%ConstructClone()

//now we use the copy for manipulation
s PV1 = newREQ.FindSegment("PV1")
set res = PV1.SetValueAt(RET,3.1)
Quit request

#ObjectScript #Ensemble
Product version: Ensemble 2018.1

Source URL:https://community.intersystems.com/post/how-can-i-add-two-values-segment-field-separated