我称之为标量函数
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
self.view = view
// vertical stack view (full screen)
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.alignment = .center
view.addSubview(stackView)
NSLayoutConstraint.activate([
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
stackView.topAnchor.constraint(equalTo: view.topAnchor),
])
// view (100x100)
let fixedSizeBlueView = UIView()
fixedSizeBlueView.translatesAutoresizingMaskIntoConstraints = false
fixedSizeBlueView.backgroundColor = .blue
stackView.addArrangedSubview(fixedSizeBlueView)
NSLayoutConstraint.activate([
fixedSizeBlueView.widthAnchor.constraint(equalToConstant: 100),
fixedSizeBlueView.heightAnchor.constraint(equalToConstant: 100),
])
// view (100x100)
let fixedSizeRedView = UIView()
fixedSizeRedView.translatesAutoresizingMaskIntoConstraints = false
fixedSizeRedView.backgroundColor = .red
stackView.addArrangedSubview(fixedSizeRedView)
NSLayoutConstraint.activate([
fixedSizeRedView.widthAnchor.constraint(equalToConstant: 100),
fixedSizeRedView.heightAnchor.constraint(equalToConstant: 100),
])
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
在此存储过程中
CREATE FUNCTION dbo.TryConvertInt(@Value varchar(200))
RETURNS INT
AS
BEGIN
SET @Value = REPLACE(@Value, ',', '')
IF ISNUMERIC(@Value + 'e0') = 0
RETURN NULL
IF (CHARINDEX('.', @Value) > 0 AND CONVERT(bigint, PARSENAME(@Value, 1)) <> 0)
RETURN NULL
DECLARE @I bigint = CASE
WHEN CHARINDEX('.', @Value) > 0
THEN CONVERT(bigint, PARSENAME(@Value, 2))
ELSE CONVERT(bigint, @Value)
END
IF ABS(@I) > 2147483647
RETURN NULL
RETURN @I
END
GO
我得到了错误
找不到“ dbo”列或用户定义的函数或聚合“ TryConvertInt”,或者名称不明确
我发现了类似的问题,但他们的答案没有帮助,或者我不知道有什么问题
答案 0 :(得分:1)
问题是tb_Items_Master.item_auto_code = select dbo.TryConvertInt(@identifier)
。不确定这是标量函数还是表值函数。我假设是前者,但我将发布您如何引用两者:
标量函数
tb_Items_Master.item_auto_code = dbo.TryConvertInt(@identifier)
表值函数
tb_Items_Master.item_auto_code = (SELECT dbo.TryConvertInt(@identifier))
或
--In your `FROM` clause
CROSS APPLY dbo.TryConvertInt(@identifier) TCI
WHERE ...
OR tb_Items_Master.item_auto_code = TCI.[column name] --I don't know what the name of the column returned it
--So you'll need to amend that
但是,该函数隐含,其名称是试图将varchar
转换为int
并且不会失败的函数?在SQL Server中已经有一个名为TRY_CONVERT
的函数,因此您可以这样做:
tb_Items_Master.item_auto_code = TRY_CONVERT(int,@identifier)