SQL - Change row/column structure of existing query -
i'm die hard excel vba fan , having make transition basic sql based piece of software. have managed adapt existing query needs (still not sure how !) further tweek :)
the query is:
parameters [date from] datetime, [date to] datetime, [site group] text;
select contacts.name, dataprofile.date, dataprofile.totalunits
(lookup inner join groups on lookup.lookup_id = groups.lookup_id) inner join (contacts inner join (points inner join dataprofile on points.id = dataprofile.point_id) on contacts.id = points.contacts_id) on groups.link_id = contacts.id
(((lookup.lookup_name)=[site group]) , ((dataprofile.date) between [date from] , [date to]) , ((points.type)='electricity') , ((dataprofile.type)=0))
, contacts.group_1=[client group]
order contacts.name, dataprofile.date;
this produces list of daily totals site day , looks :
site.......date.........value
site 1....01/01/13...444.7
site 1....02/01/13...861.5
site 1....03/01/13...850.0
etc...
is possible write query output :
site.....01/01/13....02/01/13....03/01/13
site1....444.7.......861.5.........850.0
site2....111.1.......222.2.........333.3
etc...
it make life easier have 1 row per site rather many. @ moment coding excel adapt data - it's long , not efficient. if sql output in format kind of office god !!!
any help/advise/guidence welcome :)
what version of sql running? can use pivot?
http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx