473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Show Multiple rows of data in line line

I have data in 2 tables (master-detail concept) I want to present results in the query with all details in one row. I'm working in SQL 2005, I do not know number of det per master... Please help...
Data:
Master Table: Details Table:
ID FF1 ID FFd1 FFd2
1 User1 1 DetB DetA
2 User2 1 DetC DetH
2 DetA DetC
2 DetD DetF
2 DetG DetH
Expected result:
1 User1 DetB DetA DetC DetH
2 User2 DetA DetC DetD DetF DetG DetH

Note - thanks to CK9663 for answer re CSV file - it works OK..
May 31 '12 #1

✓ answered by Rabbit

I'm not sure why you don't want to use pivot, it's the preferred method.

You don't have to link it 8 times, just pivot it.

Union the two fields, run a ROW_NUMBER() on it, and then pivot.

6 2439
ck9663
2,878 Expert 2GB
Here, read this.

Happy Coding!!!


~~ CK
May 31 '12 #2
Rabbit
12,516 Expert Mod 8TB
Use the FOR XML PATH in a subquery to string it together.

Expand|Select|Wrap|Line Numbers
  1. SELECT masterID,
  2.    (
  3.       SELECT detailField + ' '
  4.       FROM detailTable AS d
  5.       WHERE d.foreignID = m.masterID
  6.       FOR XML PATH('')
  7.    ) AS strungTogether
  8. FROM masterTable AS m
May 31 '12 #3
Thanks - it works but it concatenates all details together; I guess I was not explaining the result clearly - it needs to have each det info as a separate column, but in one record:
Max # of detailes is 8

ID User F1 F2 F3 F4 F5 F6 F7 F8
1 User1 DetB DetA DetC DetH null null null null
2 User2 DetA DetC DetD DetF DetG DetH null null
May 31 '12 #4
Auch!! This looks complex..... Any way without PIVOT? I find out there is max 8 details. I do not want to link the files 8 times either...
May 31 '12 #5
Rabbit
12,516 Expert Mod 8TB
I'm not sure why you don't want to use pivot, it's the preferred method.

You don't have to link it 8 times, just pivot it.

Union the two fields, run a ROW_NUMBER() on it, and then pivot.
May 31 '12 #6
I guess its time to learn the PIVOT.... Thanks for help to both of you...
May 31 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: merdaad | last post by:
I am trying to read multiple rows from an SP into a datalist. I can easily read and display multiple rows if I use a select statement but when I call an SP to send me a few rows, I only get back...
5
by: Arsen V. | last post by:
Hello, What is the optimal way to insert multiple rows (around 1000) from a web application into a table? The user enters multiple lines into a text box (up to 10,000). The ASP.NET...
3
by: manjub | last post by:
Hi, I am trying to add ability to delete multiple rows from a DataGridView in my application. When user selects multiple rows and presses delete button, I want to show a message asking to user...
9
by: kencana | last post by:
Hi all, I am a new bie in SOAP and PHP.I got one question about the data retrieval. I am able to retrieve the data successfully from my database. this is my sql statement: select roadname from...
1
by: Sanjaylml | last post by:
I have a form through which, e-mail address of parties are showing through datasheet mode. Is their any way to club the data of multiple rows in one column? Like : ajaimathur@rediffmail.com...
1
by: boss1 | last post by:
i m having problem with inserting data into oracle db using php. i need to how to fetch fetch multiple row's data from a table in html form and insert into oracle db at a time. may be looping is...
3
by: =?Utf-8?B?S2F5xLFoYW4=?= | last post by:
In my project,i added datagridview to my form , i transfered my table to datagridview and added multiple rows and when i called dataadapther.update ,,result is ok. But when i tried it for the...
2
by: emceemic | last post by:
Is there a way to show multiple rows per row if required? For example, say the table I currently have show the following data: Impact to Business, Business Owner Name, ...
6
by: Jeremy Goodman | last post by:
Access 2007; Merging records containing multivalue drop down lists. I have a database showing legislation information divided by State/territory. The database needs to be able to show the info...
1
by: apssiva | last post by:
Hi, how? id,username,subject 1,AAAA, EnglishI 1,AAAA, MathsI 1,AAAA, MathsII 1,AAAA, EnglishII
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.