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
remove =
in the WHERE
clause
...
WHERE (CHARINDEX('t', TBL_CS_LINKS.LINK_URL) > 0) OR ...
According to Docs: CHARINDEX MSDN 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.
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
WHERE =
is your problem. just change it to WHERE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.