C
chuck
Sometimes you start off on a path and neglect looking for alternatives. I
believe i'm on such a path and need some help.
I asked a similar question last week and got an answer that worked for
SQL2005 (using "for XML path('') ). Unfortunately, I'm stuck with using SQL
2000 for now and need a solution which will work with that.
I have a table which looks like this:
tableB:
Id col1 col2
1 1 frank
2 1 chuck
3 2 bob
4 3 steve
5 33 linda
6 2 julie
I want to be able to convert the col2 values to a single row based on the
col1 value. I also need to be able to so this from a SELECT statement so
that I can put the SELECT string as the rowsource property of an Access
listbox.
So, I would want the resulting table to look like this:
col1 col2
1 frank,chuck
2 bob,julie
3 steve
33 linda
I am able to create this stored procedure which does just that.
ALTER PROCEDURE dbo.Column_to_Row (@myval as int)
AS
DECLARE @col2 VARCHAR(1024)
SELECT @col2 = COALESCE(@col2 + ' | ','') + col2 FROM tableA WHERE col1
= @myval
SELECT col2 = @col2
RETURN
Unfortunately, I can't call a storedprocedure from within a SELECT
statement.
Perhaps I can use a function to do the same but I have not been successful
in finding the right syntax.
Help please!
If you need more information as to what I need to achieve, here goes. In
Access, I have a form with a subform. The main form is linked to TableA and
the subform is linked to TableB. The "Link Master Fields" and "Link Child
Fields" properties on the subform are set to "col1"
tableA:
col1 colA
1 blond
2 red
3 brown
33 auburn
tableB:
Id col1 col2
1 1 frank
2 1 chuck
3 2 bob
4 3 steve
5 33 linda
6 2 julie
I want to be able to output the two tables like this:
1 blond frank,chuck
2 red bob,julie
3 brown steve
33 auburn linda
Thanks
Chuck
believe i'm on such a path and need some help.
I asked a similar question last week and got an answer that worked for
SQL2005 (using "for XML path('') ). Unfortunately, I'm stuck with using SQL
2000 for now and need a solution which will work with that.
I have a table which looks like this:
tableB:
Id col1 col2
1 1 frank
2 1 chuck
3 2 bob
4 3 steve
5 33 linda
6 2 julie
I want to be able to convert the col2 values to a single row based on the
col1 value. I also need to be able to so this from a SELECT statement so
that I can put the SELECT string as the rowsource property of an Access
listbox.
So, I would want the resulting table to look like this:
col1 col2
1 frank,chuck
2 bob,julie
3 steve
33 linda
I am able to create this stored procedure which does just that.
ALTER PROCEDURE dbo.Column_to_Row (@myval as int)
AS
DECLARE @col2 VARCHAR(1024)
SELECT @col2 = COALESCE(@col2 + ' | ','') + col2 FROM tableA WHERE col1
= @myval
SELECT col2 = @col2
RETURN
Unfortunately, I can't call a storedprocedure from within a SELECT
statement.
Perhaps I can use a function to do the same but I have not been successful
in finding the right syntax.
Help please!
If you need more information as to what I need to achieve, here goes. In
Access, I have a form with a subform. The main form is linked to TableA and
the subform is linked to TableB. The "Link Master Fields" and "Link Child
Fields" properties on the subform are set to "col1"
tableA:
col1 colA
1 blond
2 red
3 brown
33 auburn
tableB:
Id col1 col2
1 1 frank
2 1 chuck
3 2 bob
4 3 steve
5 33 linda
6 2 julie
I want to be able to output the two tables like this:
1 blond frank,chuck
2 red bob,julie
3 brown steve
33 auburn linda
Thanks
Chuck