dongqianwei6664 2017-04-05 10:45
浏览 59
已采纳

Sql错误说“语法不正确”=“

In this sql I just want to check in "ON" clause b.block='False'.Because sometime "profileview " table values are empty. I just want ,If user_fullinfo values matches in profileview with this condition b.block='False' It should be display,If values are not there in profile view then also it should be display,

SELECT  a.* FROM user_fullinfo a left join profileview b on
CASE
WHEN a.id=b.rid and b.rid='105' THEN 
b.block='False' 
END
where gender != 'Male' and (DATEDIFF(YY,dob,GETDATE()) Between '10' and '100') and (a.heightid between 58 and 65) and( a.complexionid = '3' or a.complexionid = '4' or a.complexionid = '5') and a.bodytypeid = '4' and a.marital_statusid = '3'

it says sql error (102) :incorrect syntax near "=".. Please give solution..

  • 写回答

2条回答 默认 最新

  • dongyi7513 2017-04-05 10:48
    关注

    Boolean expressions are not suitable as values, such as the value for a case. My advice is to remove the case entirely and just use boolean logic. Something like this:

    select a.*
    from user_fullinfo a left join
         profileview b
         on (a.id = b.rid and b.rid = '105' and b.block = 'False') or 
            ( not (a.id = b.rid and b.rid = '105' and b.block = 'False') and
              gender <> 'Male' and (datediff(year, dob, getdate()) Between 10 and 100) and
              (a.heightid between 58 and 65) and
              (a.complexionid in (3, 4, 5)) and
              a.bodytypeid = 4 and a.marital_statusid = 3
            );
    

    Notes:

    • The standard for SQL inequality in SQL is <>, although != is also widely accepted.
    • Don't use single quotes around numeric constants. between '10' and '100' is not the same as between 10 and 100.
    • I doubt that this version or your case version really does what you want. There is no correlated between the two tables for the second condition.

    This should solve your syntax problems. The logical problem is a different issue. I would suggest that you ask another question, with sample data, desired, results, and an explanation of the logic.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度