I'm trying to understand what this code does..This snippet is a part of a stored proc. And @serv_nm and @db_n are the input parameters.

execute immediate with quotes
'insert into #temp_seno_list (se10,queueId,reasonId,statusId,refDate)
location '''||@serv_nm||'.'||@db_n||'''
{
select distinct se10, queue_id, referral_reason_id, referral_status_id, referral_queue_dt from referrals
where queue_id = ' || @queueId || ' order by se10
};';

Can someone tell me as why three single quotes are used in it(I've marked it in red).
Also i'd like to know the diff between exec immediate and exec immediate with quotes..
Thanks
Paddy