0

I need to convert this SQL query to nhibernate

declare @i int set @i=2
while (@i>0)
begin 
insert into #tmp_table3 (id , descr , RangeType , createdate )
select  * from AgeRanges as ar where AgeRangeID in (
select AgeRangeID as id from AgeRangeDetails where  agerangeid in
(select AgeRangeID from agerangedetails group by AgeRangeID having COUNT(AgeRangeID)=2)  
and agestart =(select AgeStart from #tmp_table2 where id=@i)
and AgeEnd = (select AgeEnd from #tmp_table2 where id=@i)
and Payment = (select Payment from #tmp_table2 where id=@i)
group by AgeRangeID)
and AgeRangeType=0
and AgeRangeID<>5 
set @i=@i-1
end
select id from #tmp_table3 where id in
(select id from #tmp_table3 group by id having COUNT(id)=2) group by id

can someone help me to do this. thanks

1
  • 1
    This looks like quite a bit of work. Can you please tell us which part you actually struggle with? Commented May 22, 2012 at 6:03

1 Answer 1

2

This is quite a custom bit of SQL, it has a while loop, tmp tables and variables. For this reason you are only going to be able to either create a Stored Procedure or use a named query.

a) create a Stored procedure and call it using:-

session.CreateSqlQuery("exe sp_name")...

more details...

b) create a named query in mapping and call it like this:-

session.GetNamedQuery("MyNamedQuery")...

more details...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.