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
 General SQL Server Forums
 New to SQL Server Administration
 consolidate tables

Author  Topic 

THM
Starting Member

4 Posts

Posted - 2011-11-04 : 12:08:19
Dear all,

i'm not sure that this is can be done but what i want to do is consolidate data in my database the following data is held in the SAMPLE table. I want to consolidate entrys based on rocktype. so that is to entry next to each other have the same rock type there they can become one entry with the FROM from the first and the TO from the second. see bellow. I'm not sure if this can be done with SQL, any help will be great.

holeid projectcode from to rocktype
sl1 test 1 2 dol
sl1 test 2 4 dol
sl1 test 4 7 mpy
sl1 test 7 8 mpy
sl2 test 1 2 fos
sl2 test 2 3 fos
sl2 test 3 50 mpy


I would like to look like this....
holeid projectcode from to rocktype
sl1 test 1 4 dol
sl1 test 4 8 mpy
sl2 test 1 3 fos
sl2 test 3 50 mpy

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-04 : 12:58:13
[code]
select holeid,projectcode,min(from) as from,max(to) as to,rocktype
from table
group by holeid,projectcode,rocktype
[/code]

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

Go to Top of Page
   

- Advertisement -