thormayer
thormayer

Reputation: 1070

Left join with 3 tables where clause incorrect syntax

I'm trying to create a JOIN across 3 tables with a WHERE clause, but I get an error:

'Incorrect syntax near '=' '.

I dunno what I've got wrong ?

This is my statement :

select 
    TBL_CS_PROJECT.NAME ,
    TBL_CS_LINKS.LINK_URL , 
    TBL_CS_CLICKS.CLICK_COUNT 
from 
    TBL_CS_PROJECT 
left join 
    TBL_CS_LINKS on TBL_CS_PROJECT.PROJECT_ID = TBL_CS_LINKS.PROJECT_ID 
right join 
    TBL_CS_CLICKS on TBL_CS_LINKS.LINK_ID = TBL_CS_CLICKS.LINK_ID 
WHERE =  (CHARINDEX('t', TBL_CS_LINKS.LINK_URL) > 0) 
    OR  (CHARINDEX('t', TBL_CS_PROJECT.NAME) > 0) 
order by   
    TBL_CS_PROJECT.NAME

Upvotes: 0

Views: 121

Answers (3)

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79929

You are missing the expression after the WHERE clause to compare it to the expression (CHARINDEX('t', TBL_CS_LINKS.LINK_URL) > 0) thats how the = operator works:

....
WHERE =  (CHARINDEX('t', TBL_CS_LINKS.LINK_URL) > 0) 
OR  (CHARINDEX('t', TBL_CS_PROJECT.NAME) > 0) order by   TBL_CS_PROJECT.NAME

Remove the = operator :

   ...
   WHERE CHARINDEX('t', TBL_CS_LINKS.LINK_URL) > 0
     OR  CHARINDEX('t', TBL_CS_PROJECT.NAME) > 0
   order by   TBL_CS_PROJECT.NAME

Upvotes: 1

DiverseAndRemote.com
DiverseAndRemote.com

Reputation: 19888

WHERE = is your problem. just change it to WHERE

Upvotes: 1

John Woo
John Woo

Reputation: 263713

remove = in the WHERE clause

...
WHERE (CHARINDEX('t', TBL_CS_LINKS.LINK_URL) > 0)  OR ...

According to Docs: CHARINDEXMSDN Doc

CHARINDEX - Searches an expression for another expression and returns its starting position if found.

This is already a boolean expression:

(CHARINDEX('t', TBL_CS_LINKS.LINK_URL) > 0) 

so your WHERE clause doesn't need = sign.

Upvotes: 3

Related Questions