SQLTeam.com | Weblogs | Forums

T-sql 2012 select with different types of data


#1

I need to come up with a way to uniquely define how data will appear on the different parts of the t-sql 2012 that is generated. The only thing that the two part of the report will have in common is the customer name and customer number. The dates used come from different tables.

The data for the first part will look like the following and will need to be grouped by cso_date:

Customer number customer name cso_date item_number
45 customer1 12/03/2001 16
45 customer1 9/12/2010 15
45 customer1 9/12/2010 24
45 customer1 9/12/2010 82
45 customer1 11/03/2010 07
45 customer1 11/03/2010 16

Table defintions
Customer number int,
customer name varchar(30),
cso_date datetime,
item_number int

The data for the second part will look like the following and will need to be grouped by attend_date:

Customer number customer name attend_date Course Number
45 customer1 11/03/2011 2256
45 customer1 9/12/2012 1803
45 customer1 9/12/2012 5689
45 customer1 9/12/2012 1288
45 customer1 1/03/2013 1288
45 customer1 11/03/2013 1803

Table defintions
Customer number int,
customer name varchar(30),
attend_date datetime,
Course Number int

The t-sql that I write, I keep getting all the same data in all the same rows.

Thus can you tell me how to write the t-sql so that I can uniquely define rows for the different parts of the data that is required?


#2

Can you show us the output that you'd like to have produced? What SQL code have you produced so far and what results did you get?