SQL Expression to extract part of a string divided by dashes
Hi,
I have a field (Tag_Num) in an Access database that contains a heap of values that look something like this;
12345-1234-ABC-40-CG1
12345-2868-ACC-40-CG1
12345-4897-ACC-40-CG1
12345-7874-BGC-40-CG1
12345-8756-BXC-40-CG1
12348-123-ABC-40-CG1
12348-257-HJG-40-CG1
12348-389-UIO-40-CG1
12348-487--40-CG1
12348-575-YUO-40-CG1
I want to be able to extract all the five sections separated by dashes (-) into separate columns. So far I have been trying to
do this using the Mid function which has only worked on the first few numbers since they are all only 5 digits long. For
example;
SELECT Mid([Tag_Num],1,5) AS Area1
FROM [table_name]
ORDER BY Mid([Tag_Num],1,5);
This will give me the following results;
Area1
12345
12345
12345
12345
12345
12348
12348
12348
12348
12348
If I try and do the same to extract the next few numbers after the fist dash I use this SQL code;
SELECT Mid([Tag_Num],7,3) AS Area2
FROM [table_name]
ORDER BY Mid([Tag_Num],7,3);
This will give me the following results;
Area2
1234
2868
4897
7874
8756
123-
257-
389-
487-
575-
The problem is obviously that it gets the dashes in. A similar thing occurs for the next few columns.
Any ideas how I can separate my Tag_Num column into 5 separate columns using the dash (-) as a divider?
:confused::eek::cool::confused: