我试图在插入查询中执行标量值函数。我正在使用 sql 参数集合,但仍然坚持使用它。
询问
Insert into PackageProducts values (@id, @name, @prodId, @prodCode)
// 当这个查询执行时,我想调用一个标量值函数来获取@prodCode 的值
功能
create function getProdCodeById(@id uniqueidentifier) returns varchar(15)
begin
declare @code varchar(15)
select @code=ProductCode from Products where ID=@id
return @code
end
我正在尝试做的事情
//create command, connection etc.. after than
DbParameter param = createParameter() ; // returns an empty parameter
param.Name = "@prodCode";
param.Value = String.Format("getProdCodeById('{0}')", 5);
当我执行时,它将参数值作为字符串..该函数永远不会被执行。你能告诉我我在这里做错了什么吗?