:#PCA=Campaign//CampId//CampDesc//CampBusId = 2
:#PE=PubEdition//EdId//EdCode//EdCampId = :#PCA
:#PCT=ContactType//ContTypeCd//ContTypeDesc//ContTypeUsrId in (21, 25)
:#PCC=Country//CtryId//CtryName//CtryId in (1,2)
:#lS=Status//StatCd//StatDesc//StatUsrId = 21
:#PT=TelecomKind//TeleKindCd//TeleKindDesc
if not (object_id('tempdb..#ClientList') is null) drop table #ClientList
create table #ClientList (ClientTableCd char(2), ClientId int)
IF ((SELECT cursor_status('global','clientcursor')) != -3) DEALLOCATE ClientCursor
declare ClientCursor cursor forward_only global for
SELECT AcctTableCd ClientTableCd, AcctRecordId ClientId
FROM Account, AccountItems,
(select ProdId from Product
where ProdTableCd = 'ED' and ProdRecordId = :#PE
union select ProdId from Product, PubSection
where ProdTableCd = 'PS' and SecId = ProdRecordId and SecEdId = :#PE) Products
WHERE AcctId = ItemAcctId and ItemCampId = :#PCA
and ProdId = ItemProdId and AcctUsrId = 21 and (('' in :#lS) or (ItemStatCd in :#lS))
EXEC sps_EdPhoneList 21, :#PCT, 'F', 'E', 1, 0, :#PE
SELECT StaffName "Salesrep", ClientName "Client",
case :#PT when 'E' then TelType2 when 'F' then TelType1 else '' end TelType,
case :#PT when 'E' then TelNumber2 when 'F' then TelNumber1 else 'n/a' end Number,
Salutation, ContactName, GivenNames, Surname, Position
FROM Address, #ClientList
left join Assignments left join Staff on StaffId = AssnStaffId
on AssnTableCd = ClientTableCd and AssnRecordId = ClientId
and AssnUsrId = 21 and AssnForTableCd = 'ED' and AssnForRecordId = :#PE,
(select 'IN' TableCd, InstId RecordId, InstAddrId
from Institute
union
select 'FA' TableCd, FacId RecordId, InstAddrId
from Institute, Faculty where InstId = FacInstId
union
select 'PR' TableCd, ProgId RecordId, InstAddrId
from Institute, Faculty, Program where InstId = FacInstId and FacId = ProgFacId) Source
WHERE TableCd = ClientTableCd and RecordId = ClientId
and AddrId = InstAddrId and AddrCtryId = :#PCC
and (((:#PT = 'E') and (isnull(TelNumber2,'') != ''))
or ((:#PT = 'F') and (isnull(TelNumber2,'') = '') and (isnull(TelNumber1,'') != ''))
or (not (:#PT in ('E','F')) and (isnull(TelNumber2,'') = '') and (isnull(TelNumber1,'') = '')))
ORDER BY StaffName, ClientName
deallocate global ClientCursor
drop table #ClientList
Ideas? I don't recognize the :# syntax from anything I've interfaced with before.
Thanks!