SQL中三重连接的测试用例

时间:2016-05-01 21:04:21

标签: sql unit-testing

SELECT triple_join('A multiple join on the Equipment, EquipmentTypes, and
  RentalInfo works effectively: ',
    CASE WHEN
      (SELECT name, e.riid, rental_start, in_use FROM Equipment AS e JOIN 
        EquipmentTypes ON equipment_type = etid JOIN RentalInfo AS ri ON
        e.riid = ri.riid)
= ('Enabler 420', 1, '20141107', 1)
  THEN 'Passed' ELSE 'Failed' END
  );

这是测试我的联接是否有效工作的代码。但是,当我运行代码时,它表示我在","附近有语法错误。有人能告诉我发生了什么吗?

P.S。:设备,设备类型和租赁信息是我已定义的表格,并且已插入'在另一个文件中。

1 个答案:

答案 0 :(得分:0)

不确定它是否解决了问题,但调试比你的更简单。此外,它将解决多个匹配记录的问题:

SELECT triple_join('A multiple join on the Equipment, EquipmentTypes, and
  RentalInfo works effectively: ',
    CASE WHEN EXISTS (
        SELECT TOP 1 1 FROM Equipment AS e 
        INNER JOIN EquipmentTypes as et ON e.equipment_type = et.etid 
        INNER JOIN RentalInfo AS ri ON e.riid = ri.riid
        WHERE name = 'Enabler 420' and e.riid = 1 and 
            rental_start = '20141107' and in_use = 1) 
    THEN 'Passed' ELSE 'Failed' END
);

如果问题仍然存在,请尝试单独运行内部“SELECT”和函数,看看导致问题的原因。