MS query to obtain a single row of data with multile rows

Dear experts,

I would like to find out how can I modify my query to change the way my query result displays.

Here is my query:

SELECT product_id, warehouse_loc
FROM inventory
ORDER BY product_id

My display result will look like this:

product_id              warehouse_loc
NX-1233-01             B1-2
NX-1223-01             B2-2
Nx_1223-01             B3-1

Is there a way that I can modify my result to look like this:

product_id              warehouse_loc
NX-1233-01             B1-2
                                B2-2            
                                B3-1

Thanks
Kinderly WadeprogrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Not without a fair amount of pain.  It is the opinion of most developers that cosmetics like this are better served in whatever reporting application you are using as opposed to in T-SQL, as doing it that way in a set would hose up grouping/sorting.

For example, in SQL Server Reporting Services (SSRS) in the textbox for the product_id column the HideDuplicates property can be set to True, which would blank out all 'duplicates' beyond the first row.
1
sdstuberCommented:
SELECT CASE WHEN rn = 1 THEN product_id END product_id, warehouse_loc
    FROM (SELECT product_id,
                 warehouse_loc,
                 ROW_NUMBER() OVER(PARTITION BY product_id ORDER BY warehouse_loc) rn
            FROM inventory)
ORDER BY product_id, warehouse_loc;


This simply numbers each row 1,2,3,... for each product id,
 if row number = 1 (i.e. the first row for that product)  then display the id, otherwise return NULL (blank) for the product id
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Najam UddinCommented:
Do you want 3 rows with blank in 2 and 3rd row for first column?
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<For example, in SSIS in the textbox for the product_id column the HideDuplicates property can be set to True, which would blank out all 'duplicates' beyond the first row.>>

 Same is true in the Access report writer, but not in a query.

Jim.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
typo correction, in my original comment I had SSIS instead of SQL Server Reporting Services (SSRS).   Corrected.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.