Seasons Greetings,
You can split the Code string into multiple rows very
easily with the RAC (Relational Application Companion)
utility.RAC runs on any version of Sql Server 2000.
At the very least you can install the MSDE version of
server (which is easy to get).You can then export your
Access data to server,import Access data to server,
use an ADP,link to your Access table(s) from the server etc.
RAC can do many things from complex crosstabs to
analyzing hierachies.And it can usually do them without
any sql coding.It's intended to solve problems quicky
and easily.Given any task there are many options to
choose from.So you have flexibility along with easy of use.
You will find that RAC is in many ways similar to the Access
crosstab query.But it can do much more than crosstabs
.
Advanced sql users will find that RAC is tightly integrated
with the server so you can use server sql within RAC to
do just about anything (see the @select parameter in Help).
For example, here is a simple RAC solution for your sample data.
To make things easy we'll create the data on the server.
create table #DG ([RECORD #] int primary key,CODE varchar(100))
go
insert #DG values(1,'180 185')
insert #DG values(2,'1A0 1A3 104 1A4 109')
--select * from #DG
Here we split the CODE string based on the sequence (position)
of each delimited string from left to right.RAC can be driven thru
its own GUI or executed in batch just like any server stored procedure.
Here is the batch execute.
Exec Rac
-- Specify the method of splitting.
@split='[position]',
-- Specify what columns should repeat for each split string part.
@rows='[RECORD #] & [position] ',
-- Specify the column to be split
@pvtcol='CODE',
@from='#DG', -- Just like a server FROM statement.
-- RAC also has a @where statement
-- just like the server WHERE.
-- We give the string parts the column name 'col1'.
-- You could give any name,ie @rank='str' would
-- name the column 'str1'.
-- RAC has its own SELECT option with many
-- special features.You could use it to rename
-- 'col1' or do just about anything else you wanted
-- using any valid server syntax.
@rank='col',
-- Delimiter used in CODE, ie. a blank (' ').
@separator=' ',
@rowbreak='n', -- Similar to breaking on columns in Access Reports
-- Here we don't want duplicate [RECORD #]'s
-- to be suppressed,so we display each one
('n'='no').
@defaults1='y',
-- Eliminate position from the result.
@defaultexceptions='[position]'
Result:
RECORD # col1
-------- ----
1 180
1 185
2 1A0
2 1A3
2 104
2 1A4
2 109
As stated above, with any task you have many options
to choose from.Here we split CODE based on the string
part values (ie. order them by value).We also create
counters that may be used in subsequent processing
or just for display.
Exec Rac
@split='[value]',
@rows='[RECORD #] & [value] ',
@pvtcol='CODE',
@from='#DG',
@rank='col',
@separator=' ',@rowbreak='n',@defaults1='y',
-- Define a counter of CODES within each [RECORD #]
-- We choose to give the counter column the name 'CODEcnter'
@rowcounters='[RECORD #]{CODEcnter}',
-- Define a counter over the entire result.This is the internal
-- RAC record counter.It is always column 'rd'.
@tablecounter='y',
@defaultexceptions='[value]'
Result:
rd RECORD # CODEcnter col1
----------- -------- --------- ----
1 1 1 180
2 1 2 185
3 2 1 104
4 2 2 109
5 2 3 1A0
6 2 4 1A3
7 2 5 1A4
Note that *no* sql coding was necessary for any of this.
Of course there are many other options.You could
save the result to a server table,create complex
expressions easily etc.
For all the details on RAC and QALite (a free adminstration
and querying tool for MSDE) visit:
www.rac4sql.net
Happy Holidays to All from
RacTeam