sql server - nhibernate complex query of sql with a group by ROLLUP() of permenant table union all derived query -


how convert following sql contains case count, group by, union nhibernate? complex sqql group rollup() of permanent table union derived query columns

select   case           when grouping([business_unit]) = 1 'total'           else [business_unit]         end [business_unit]       , sum(injuryillnessttlcount) injuryillnessttlcount   (  select i.incident_id        ,b.business_unit      ,case           when (i.injury_illness_type_id=4  ) 1  --'injury/illness (near miss high severity potential)'           else 0      end injuryillnessttlcount  tblincident  join tblbusiness_unit b on i.bus_unit_id = b.bus_unit_id  --where (convert(varchar(10),i.create_dt, 111) between '2015/01/12' , '2015/05/12')   union  select 0 incident_id                ,b.business_unit        ,0 injuryillnessttlcount     tblbusiness_unit b   ) abc  group rollup(abc.business_unit)

when comes complicated queries, conversion nhibernate either not possible or not worth it. 2 cents go with,

var query = <your query>;  var session = sessionfactory.opensession(); var result =session.createsqlquery(query)                 .list(); 

where query directly executed.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -