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 2005 Forums
 Transact-SQL (2005)
 Complex Insert Into Query

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2010-10-20 : 13:43:32
This is a bit difficult to explain...

I get monthly data and have this monthly data back to June. I want to take the average of the monthly data for every month and dump it inot a table. I have my queries to get the monthly avg of the data. However I would like my table to have the monthly avg and the person's name associated with the data. For example.

NAME.....Jun2010.....July2010......Aug2010

John.......5.3.........5.6...........6.7
Jane.......4.6.........7.8...........6.3
David......1.2.........2.4...........5.6

However, the from month to month a person may be added or removed. I want the table to be based off of the most current month's data (AUG)So how do i execute these three insert into queries and only input data from previous months that are in August's month? If I execute the queries seperately I get...


NAME.....Jun2010.....July2010......Aug2010

John.......NULL.........NULL.........6.7
Jane.......NULL.........NULL.........6.3
David......NULL.........NULL.........5.6
NULL.......NULL.........1.3..........NULL
NULL.......NULL.........3.3..........NULL
NULL.......NULL.........5.5..........NULL
NULL.......1.2......... NULL.........NULL
NULL.......1.3......... NULL.........NULL
NULL.......3.2......... NULL.........NULL

Thanks for the help in advance!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-20 : 13:47:57
didnt understand which value corresponds to whom for previous months. can you elaborate?

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

Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2010-10-20 : 15:32:53
That's it, my names and values change from month to month. How do i insert everything on the correct line when i do an insert into?
Go to Top of Page
   

- Advertisement -