我有一个名为VIEW_FORM_SALE_SUBMISSION_INFO
我的查询为
select a.FormSl
from VIEW_FORM_SALE_SUBMISSION_INFO as a
where FormSl between convert(int,'113990') and convert(int,'1131000')
我的目标:
convert()
函数中的这两个值作为参数答案 0 :(得分:2)
这个怎么样?
select a.FormSl
from VIEW_FORM_SALE_SUBMISSION_INFO as a
where FormSl between @param1 and @param2
@param1
和@param2
是整数参数?
答案 1 :(得分:1)
要对此进行参数化,您可以创建一个表值函数。
CREATE FUNCTION myFunction (@lower_bound AS VARCHAR(32), @upper_bound AS VARCHAR(32))
RETURNS TABLE AS
RETURN
select a.FormSl
from VIEW_FORM_SALE_SUBMISSION_INFO as a
where FormSl between convert(int,@lower_bound) and convert(int,@upper_bound)
SELECT * FROM dbo.myFunction('11111', '22222')
在优化转换方面,你所拥有的是最佳的。
如果你想进一步改进它,不要传入字符串,首先传递int整数。