SQL: split a variable

Status
You're currently viewing only mr_b0m's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

mr_b0m

Ars Scholae Palatinae
654
Hello

I'm sending an INSERT that looks something like this, today
Code:
INSERT INTO table_name (ID, JobNo, Volume) VALUES (@'%1', '@%2', '@%3')
@%1-3 are variables that's replaced by our system. So far so good.

Here's the tricky part. A new requirement is to send a part of the JobNo (@%2), to another field as well, that we might call LineNo. For example, our system sends '12345.01' as variable @%2, and I want the '12345' part of it to go into JobNo and the '01' to go into LineNo. Does that make any sense? I haven't touched SQL before so I'm a bit lost. I've googled and some kind of string split function exists but I'm not sure on how to apply it here, if it's even possible. Mind you, I'm just trying the easy way here, if this doesn't work we'll go the long way around and make sure we have two different inputs for JobNo and LineNo.
 

mr_b0m

Ars Scholae Palatinae
654
Interesting. I do know that there will be only one '.' occurrence, and I know that the string lengths won't be changing.

However, I'm not sure how to use the instr command, can I nest it in together with the INSERT like this?

Code:
INSERT INTO table_name (ID, JobNo, LineNo, Volume) VALUES ('@%1', 'substr( '@%02' , 1 , instr( '@%02' , '.' )- 1 )',  substr( '@%02' ,  'instr( '@%02' , '.') - length( '@%02' ))', '@%3')

Feel free to smack me if it's a stupid question. :eek:
 

mr_b0m

Ars Scholae Palatinae
654
The environment is fairly simple. This is for a computer managed fluid dispensing system and everytime someone makes a dispense, it gets sent to our DB, but in addition to that it also gets sent to the customer's DB, configured with an INI file containing the INSERT string (ForwardTransaction="INSERT blah blah"). So there's not any real coding involved at this stage, just modification of the string.
 
Status
You're currently viewing only mr_b0m's posts. Click here to go back to viewing the entire thread.
Not open for further replies.