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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamically creating result columns & data based on JOIN

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-24 : 08:31:14
Matthew writes "I am currently using SQL Server 2000 SP4. Developing a website in Visual Studio 2005.

I have created a database that has a JOBS table, each row of the table has corresponding records in a JOB_TASKS table. Each job may have a different number of records in the JOB_TASKS table.

I am trying to create a query that returns a few fields of the JOBS table, then searches the JOBS_TASKS table for all related records and uses those records to create additional column names back in the query and fill in the data in the correct columns.

So if the JOBS table fields & data look like this:

JOB_ID, NAME, DATE
5000 Bob 2006-01-21
5001 John 2006-01-22


And the JOBS_TASKS table fields & data look like this:

JOB_TASK_ID, JOB_ID, TYPE, COMPLETED
1 5000 100 Yes
2 5000 200 No
3 5001 100 Yes
4 5001 200 No
5 5001 300 No



Then the query would output:

JOB_ID, NAME, DATE, TASK_100, TASK_200, TASK_300
5000 Bob 2006-01-21 Yes No
5001 John 2006-01-22 Yes No No


Note the TASK_100, TASK_200 & TASK_300 fields above are to be created dynamically depending on the maximum related records in JOB_TASKS and labeled using the TYPE field value.

The idea is to show all the jobs in a GridView and the progress of each job represented accross in columns.

Can you help?

Thanks

Matthew"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-25 : 01:30:38
See if this helps
http://sqlteam.com/forums/topic.asp?TOPIC_ID=53384

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -