I’m having a write a SORel change log report and data from the OrderRel table. The field ChgLog.Key2 contains the SONum, Line, and Rel data I need but in a tilde delimited manner.
I’ve been working to split it out and got the SO number to work via the case below, but I can’t get Line or Release to work.
Case
When ChgLog.Key2 like ‘%~%’
Then LEFT(ChgLog.Key2, PATINDEX(‘%~%’, ChgLog.Key2) -1)
End
For LINE, I thought I was onto something by modifying the Case above with Substring but I can’t get the syntax correct.
For REL, I was trying RIGHT instead of Left in the syntax but it returns too much data, ie: 162~1~21 instead of just 21 for the Rel number.
case
When ChgLog.Key2 like ‘%~%’
Then Right(ChgLog.Key2, PATINDEX(‘%~%’, ChgLog.Key2) )
End
I’m writing a BAQ so all I can do is a calculated field in SQL commands.
The field ChgLog.Key2 lists the SP, Line, Rel separated by ~'s: 12345~1~1. I need to split the three apart into calculated fields, so I can use them to relate to the OrderRel table.
This is a calculated field I use in one of my BAQs to split OrderHed.SalesRepList which is a list of 5 rep IDs separated by ~.
Eg: 100~240~900~923~235
It’s searching for which rep has the split of 100% and getting the value from the tilde string with this statement: [Ice].entry(1,OrderHed.SalesRepList,’~’)
case
when OrderHed.RepSplit1 = 100 then [Ice].entry(1,OrderHed.SalesRepList,'~')
when OrderHed.RepSplit2 = 100 then [Ice].entry(2,OrderHed.SalesRepList,'~')
when OrderHed.RepSplit3 = 100 then [Ice].entry(3,OrderHed.SalesRepList,'~')
when OrderHed.RepSplit4 = 100 then [Ice].entry(4,OrderHed.SalesRepList,'~')
when OrderHed.RepSplit5 = 100 then [Ice].entry(5,OrderHed.SalesRepList,'~')
end
Your example would be something like this:
For the SP: [Ice].entry(1,ChgLog.Key2,’~’)
For the Line: [Ice].entry(2,ChgLog.Key2,’~’)
For the Rel: [Ice].entry(3,ChgLog.Key2,’~’)
The 1-3 being the index of the array that the split creates.
Edit** I have used that case statement to join the SalesRep table as well, so you should be able to use it to relate to the OrderRel table.
Thanks, that’s exactly what I needed. Didn’t even need a case statement as SO / Line / Rel have their own calculated fields. The BAQ only looks for changes to the OrderRel table, so there will always be results in each column.
@jdtrent, that’s a good idea too and I may need it for another report for Shipping and AR reports later.