我需要修剪一个搜索参数,这样当输入一个数字时,它会修剪结果,使得没有前导或拖尾空格。下面是SQL。我在语法上找到了很多资源,我只是没有理解如何修剪@SearchText变量。任何帮助是极大的赞赏。 @SearchText变量用作SSRS中的参数。谢谢
DECLARE @SearchText varchar(30)
select Q.STATUS_EFF_DATE as DISP_DATE,
Q.EXPIRATION_DATE as EXP_DATE,
Q.STATUS as DISPOSITION,
QL.PART_ID,
QL.DESCRIPTION,
QL.CUSTOMER_PART_ID,
Q.NAME as CUST_NAME,
Q.CUSTOMER_ID as CUST_ID,
Q.ID as QUOTE_ID,
QP.UNIT_PRICE,
QP.QTY
from Quote_LINE QL inner join QUote Q
on QL.QUOTE_ID = Q.ID
inner join QUOTE_PRICE QP
on QP.QUOTE_ID = Q.ID
and QP.QUOTE_LINE_NO = QL.LINE_NO
where QL.PART_ID like '%' +@SearchText +'%'
or QL.DESCRIPTION like '%' +@SearchText +'%'
or QL.CUSTOMER_PART_ID like '%' +@SearchText +'%'
答案 0 :(得分:0)
使用LTRIM
删除leading
空格并使用RTRIM
删除trailing
空格。
where QL.PART_ID like '%' +LTRIM(RTRIM(@SearchText)) +'%'
or QL.DESCRIPTION like '%' +LTRIM(RTRIM(@SearchText)) +'%'
or QL.CUSTOMER_PART_ID like '%' +LTRIM(RTRIM(@SearchText)) +'%'