NutzCN Logo
问答 sql.setParam和is null怎么一起使用
发布于 1841天前 作者 yanteng0124 1779 次浏览 复制 上一个帖子 下一个帖子
标签:
SELECT
	ts.*
FROM
	t_scenic ts
WHERE
	NAME NOT IN (
		SELECT
			scenic
		FROM
			t_order_travelplan_jp
		WHERE
			orderId = @orderid
		AND scenic != @scenicname
	)
and cityId = @cityid and region = @region

上边是sql语句,下边是controller

Sql sql = Sqls.create(sqlString);
					sql.setParam("orderid", orderid);
					sql.setParam("cityid", plan.getCityId());
					sql.setParam("scenicname", plan.getScenic());

其中region参数有两种情况,region为空时需要是 region is null,但用sql.setParam("region ", region )是 region = null,怎么写最终sql才是region is null?

2 回复

把=做成变量

SELECT
	ts.*
FROM
	t_scenic ts
WHERE
	NAME NOT IN (
		SELECT
			scenic
		FROM
			t_order_travelplan_jp
		WHERE
			orderId = @orderid
		AND scenic != @scenicname
	)
and cityId = @cityid 
and 

(
CASE 
WHEN region is NULL then region is NULL
WHEN region is not NULL then region = @region
END
)

改成这样,和把=号作为变量哪个效率高?

添加回复
请先登陆
回到顶部