Originally posted by Meena
The query below results in the correct resultset in ADMIN SQL execution window.
But when I add the CREATE VIEW to it OLEDB does not execute. Failed to parse sql message is displayed.
I am trying to list the last completed date an account was contacted for a SalesCall category.Also list the accounts that were never contact for a SalesCall category. So I am doing an UNION. Create VIEW does not seem to like UNION in the query.
Any other ways of getting this done???
CREATE VIEW [sysdba].[C_V_LASTSALESCALL] AS
SELECT DISTINCT sysdba.ACCOUNT.ACCOUNTID, sysdba.ACCOUNT.ACCOUNT, sysdba.ACCOUNT.MAINPHONE, sysdba.ACCOUNT.REVENUE, sysdba.ACCOUNT.TYPE, sysdba.ACCOUNT.SUBTYPE, MAX(sysdba.HISTORY.COMPLETEDDATE) AS LASTCALLDATE FROM sysdba.ACCOUNT INNER JOIN sysdba.C_ACCOUNT_EXT ON sysdba.ACCOUNT.ACCOUNTID = sysdba.C_ACCOUNT_EXT.ACCOUNTID INNER JOIN sysdba.HISTORY ON sysdba.ACCOUNT.ACCOUNTID = sysdba.HISTORY.ACCOUNTID INNER JOIN sysdba.CONTACT ON sysdba.HISTORY.ACCOUNTID = sysdba.CONTACT.ACCOUNTID WHERE (sysdba.HISTORY.COMPLETEDUSER <> 'ADMIN') AND (sysdba.HISTORY.CATEGORY LIKE '%sales%') GROUP BY sysdba.ACCOUNT.ACCOUNTID, sysdba.ACCOUNT.ACCOUNT, sysdba.ACCOUNT.MAINPHONE,sysdba.ACCOUNT.REVENUE, sysdba.C_ACCOUNT_EXT.COIPERCENT, sysdba.ACCOUNT.TYPE,sysdba.ACCOUNT.SUBTYPE
UNION ALL
SELECT sysdba.ACCOUNT.ACCOUNTID,sysdba.ACCOUNT.ACCOUNT,sysdba.ACCOUNT.MAINPHONE, sysdba.ACCOUNT.REVENUE,sysdba.ACCOUNT.TYPE, sysdba.ACCOUNT.SUBTYPE, NULL AS LASTCALLDATE FROM sysdba.ACCOUNT WHERE (sysdba.ACCOUNT.ACCOUNTID NOT IN (SELECT DISTINCT sysdba.ACCOUNT.ACCOUNTID FROM sysdba.ACCOUNT INNER JOIN sysdba.C_ACCOUNT_EXT ON sysdba.ACCOUNT.ACCOUNTID = sysdba.C_ACCOUNT_EXT.ACCOUNTID INNER JOIN sysdba.HISTORY AS HISTORY_1 ON sysdba.ACCOUNT.ACCOUNTID = HISTORY_1.ACCOUNTID INNER JOIN sysdba.CONTACT AS CONTACT_1 ON HISTORY_1.ACCOUNTID = CONTACT_1.ACCOUNTID WHERE (HISTORY_1.COMPLETEDUSER <> 'ADMIN') AND (HISTORY_1.CATEGORY LIKE '%sales%') GROUP BY sysdba.ACCOUNT.ACCOUNTID, sysdba.ACCOUNT.ACCOUNT, sysdba.ACCOUNT.MAINPHONE, sysdba.ACCOUNT.REVENUE, sysdba.C_ACCOUNT_EXT.COIPERCENT, sysdba.ACCOUNT.TYPE, sysdba.ACCOUNT.SUBTYPE))
Further modified the query to look like this, but get fsailed to parse query in the admin exec sql window.
SELECT
sysdba.ACCOUNT.ACCOUNTID, sysdba.ACCOUNT.ACCOUNT, sysdba.ACCOUNT.MAINPHONE, sysdba.ACCOUNT.REVENUE,
sysdba .ACCOUNT.TYPE, sysdba.ACCOUNT.SUBTYPE ,(SELECT top 1 H.COMPLETEDDATE FROM sysdba.HISTORY H LEFT
JOIN sysdba.ACCOUNT ON sysdba.ACCOUNT.ACCOUNTID=H.accountid LEFT
JOIN sysdba.C_ACCOUNT_EXT ON sysdba.ACCOUNT.ACCOUNTID = sysdba.C_ACCOUNT_EXT.
ACCOUNTID LEFT JOIN sysdba.CONTACT ON sysdba.CONTACT.ACCOUNTID = sysdba.ACCOUNT.
ACCOUNTID
WHERE (H.CoMPLETEDUSER <> 'ADMIN') AND (H.CATEGORY LIKE '%sales%')
ORDER BY H.COMPLETEDDATE DESC)
FROM sysdba.ACCOUNT LEFT
JOIN sysdba
.C_ACCOUNT_EXT ON sysdba.ACCOUNT.ACCOUNTID = sysdba.C_ACCOUNT_EXT.ACCOUNTID LEFT
JOIN sysdba
.CONTACT ON sysdba.CONTACT.ACCOUNTID = sysdba.ACCOUNT.
ACCOUNTID LEFT JOIN sysdba.HISTORY ON sysdba.CONTACT.CONTACTID = sysdba.HISTORY.
CONTACTID GROUP
BY sysdba.ACCOUNT.ACCOUNTID, sysdba.ACCOUNT.ACCOUNT, sysdba.ACCOUNT.MAINPHONE,sysdba.ACCOUNT.REVENUE,
sysdba
.C_ACCOUNT_EXT.COIPERCENT, sysdba.ACCOUNT.TYPE,sysdba.ACCOUNT.
SUBTYPE ORDER BY ACCOUNT.ACCOUNT
ASC
GO
|