使用%wildcard匹配SMALLMONEY

时间:2013-02-21 20:04:32

标签: sql-server tsql

我在SQL中编写了这段代码:

alter proc verfinanfiltrado(@valor smallmoney) as
select idconta,vencimento,historico,original,formpagto,planoconta,clifor
from financeiro where original like @valor

这个程序有效,我想写一些像:

alter proc verfinanfiltrado(@valor smallmoney) as
select idconta,vencimento,historico,original,formpagto,planoconta,clifor
from financeiro where original like  % @valor % 

示例该过程适用于746.06,但我想显示所有以746开头的值,如746.06,746.10,748.12

在nvarchar的情况下

 alter proc verfinanfiltrado(@histo smallmoney) as
select idconta,vencimento,historico,original,formpagto,planoconta,clifor
from financeiro where historico  like  % @histo % 

3 个答案:

答案 0 :(得分:2)

转换列(通过字符串转换或舍入)将阻止使用索引。不要这样做。代替...

from financeiro where @value <= original and original < @value + 1

答案 1 :(得分:1)

WHERE original >= ROUND(@valor,0,1) AND original < ROUND(@valor,0,1) + 1

顺便说一下,对原始问题的评论中的xQberts解决方案也会起作用,但这是可以理解的,所以你将受益于原始的任何不足

答案 2 :(得分:0)

我用这个proc解决了

alter proc vencevalor (@valor smallmoney)as
select idconta,vencimento,pagamento,historico,original,formpagto,planoconta,clifor
from financeiro where round(original,0,1) = round (@valor,0,1)  
order by idconta desc 

感谢所有