email:
ownerType:
ownerId:
select u.fspro_userId, c.companyId, m.moduleId, '' submoduleIds, m.module from tbl_LIB_Modules m inner join tbl_LIB_Companies c on 1 = 1 inner join tbl_fspro_members u on 1 = 1 where ( m.clientTypes like '%' + c.companyPType or m.clientTypes like '%' + c.companyPType + ',%' or m.clientTypes = c.companyPType + convert( varchar, c.companyPKeyId )) and m.moduleId not in ( 34,36,37, 38,40,49,53,55,54,39,56,63,71,80,90,91,97,100,131,119,108,107,104,98,96,58,41,72 ) and c.companyPType = and c.companyPKeyId = and u.email = and u.ownerId = 21 and u.fsl_tablecode = 'MSC' and ( select count(*) from tbl_fspro_members u2 where u2.email = u.email and u2.ownerId = u.ownerId and u2.fsl_tablecode = u.fsl_tablecode ) = 1 and not exists ( select * from tbl_LIB_Accounts a where a.fspro_userid = u.fspro_userid and a.moduleId = m.moduleId and a.companyId = c.companyId ) order by m.moduleId insert into tbl_LIB_Accounts ( fspro_userid, companyId, moduleId, submoduleIds ) values( , , , )