Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 transpose

Author  Topic 

bkleen
Starting Member

5 Posts

Posted - 2010-02-25 : 14:01:32
I have the following table:

Inv#......Vend......Store#
12345.....ABC.......999
12345.....ABC.......888
12345.....ABC.......777
23456.....DEF.......666
23456.....DEF.......555
34567.....GHI.......444

I want to create a query that will display the data as follows:
Inv#......Vend......Store#'s
12345.....ABC.......999,888,777
23456.....DEF.......666,555
34567.....GHI.......444

I need to show one row for each distinct combo of Inv# and Vend and then list each store related to that combo in a separate column. I can use the "select first" and "select last" statements to show the first and last occurrence of stores per combination but not the 2nd, 3rd, etc if there are more than 2.

Sachin.Nand

2937 Posts

Posted - 2010-02-25 : 14:19:31
See this

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=140414

PBUH
Go to Top of Page

bkleen
Starting Member

5 Posts

Posted - 2010-02-26 : 08:04:38
I tried the suggested code but got a syntax error. I didn't mention that I'm using Access2007, is that code supported in Access? Also, it appears that the example is for a situation where there is data in 2 different tables, all of my data is in one single table.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-02-26 : 08:06:59
The link I had sent will work even for single table with a little bit workaround.But xml path is not supported for any version of Access.

PBUH
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-26 : 08:15:25
see 3rd scenario below

http://visakhm.blogspot.com/2010/01/multipurpose-apply-operator.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bkleen
Starting Member

5 Posts

Posted - 2010-02-26 : 08:17:09
I assume that the XML Path content is needed for the statement to work so is there a way for me to accomplish this in Access?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-26 : 08:24:52
Are you asking for Access query? then post in Access forum.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -