SQL问题 - 股票差异小于。 [英] SQL problem - Stock Discrepency with less than.
本文介绍了SQL问题 - 股票差异小于。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我写了一个程序,当当前库存低于最低要求时发送电子邮件。
这是我的代码的一部分:
Dim con 作为 新 SqlConnection
Dim cmd 作为 新 SqlCommand
con.ConnectionString = Data Source = ######; Initial Catalog = ######; Integrated Security = True
con.Open()
cmd.Connection = con
cmd.CommandText = SELECT * FROM [ + dbase + ] WHERE CurrentStock< MinimumRequired
显示一个那些当前库存低于最小值的那些,但也会显示一个或两个其他部分。例如。它的显示库存为10,最小值为2,所以它不应该显示。
我是否遗漏了上述代码中的内容?
为任何帮助干杯,
Pete
解决方案
我认为问题是与CurrentStock&的数据类型有关。 MinimumRequired。
检查数据类型。
例如。
以下案例会说2大于10
声明 @ a varchar ( 10 )
声明 @ b varchar ( 10 )
set @ a = ' 10'
set @ b = ' 2'
select case 当 @ a > @b 然后 @ a + ' 更大' @ a = @ b 然后 ' 两者相等'
else @ b + ' 更大' 结束 更高
输出:
更高
2更高
Hello,
I've written a program to send out an email when currentstock goes below minimumrequired.
Here's part of my code:
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=######;Initial Catalog=######;Integrated Security=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT * FROM [" + dbase + "] WHERE CurrentStock < MinimumRequired"
It displays all the ones that the current stock is below the minimum, but one or two other parts are being displayed aswell. E.G. its displaying stock of 10 and the minimum is 2, so it shouldnt be displaying.
Have i missed something out of the code above?
Cheers for any help,
Pete
解决方案
I think issue is with datatype of CurrentStock & MinimumRequired.
check for datatype.
for eg.
below case will say 2 is greater then 10
declare @a varchar(10) declare @b varchar(10) set @a='10' set @b='2' select case when @a >@b then @a +' is greater' when @a = @b then 'Both are equal' else @b +' is greater' end as Greater
output:
Greater 2 is greater
这篇关于SQL问题 - 股票差异小于。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文