Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
SELECT Camp.ID,
Inst.StartDate,
detail.CertScopeValue,
Actr.Actor,
Ctype.CampaignType,
'Cert'+REPLACE(Ctype.CampaignType,' ','') AS mytable
FROM CertCampaign Camp
LEFT JOIN CertInstance Inst ON Inst.CampaignId=Camp.ID
LEFT JOIN CertScope Scope ON Scope.ID=Camp.CertScopeID
LEFT JOIN CertScopeDetail detail ON detail.CampaignId=Camp.ID
LEFT JOIN CertActor Actr ON Actr.ID=Camp.CertActorId
LEFT JOIN CertCampaignType Ctype ON Ctype.ID=Camp.CampaignTypeId
LEFT JOIN (SELECT CASE when mytable='CertUserToAccount' then CertUserToAccount)t  ON Inst.ID=t.InstanceId
(SELECT CASE mytable
when 'CertAccountToRole' then 
     LEFT JOIN CertAccountToRole
when   'CertAccountToPermission' then 
    LEFT JOIN CertAccountToPermission
when 'CertRoleToPermission' then 
    LEFT JOIN CertRoleToPermission
when 'CertUserToAccount' then 
    LEFT JOIN CertUserToAccount)TypeName  ON Inst.ID=TypeName.InstanceId
WHERE Camp.ID='46722DAF-931D-4DBE-9CD6-6FCB1B42FE94' AND detail.CertScopeID=Camp.CertScopeID



ERROR:
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near ')'.
Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'JOIN'.
Posted
Updated 19-May-14 1:55am
v2

On the first look: CASE WHEN statement is incomplete. Must be ended with END word! In both cases!

Have a look here: CASE (SQL)[^]
 
Share this answer
 
For starters, I suspect the first error is caused by:

SELECT CASE when mytable='CertUserToAccount' then CertUserToAccount


as indicated by Error on line 13.

The 'SELECT' statement is aliased to 't', but where is it selecting anything from?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900