Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 基于自定义公式的计算,存储在db表中_Sql Server_Stored Procedures - Fatal编程技术网

Sql server 基于自定义公式的计算,存储在db表中

Sql server 基于自定义公式的计算,存储在db表中,sql-server,stored-procedures,Sql Server,Stored Procedures,我有一个带有自定义函数(函数名和参数列表)的表,并使用它计算产品成本的百分比。我需要做的是SQL(SQLServer2008) 这是存储自定义函数的表 CREATE TABLE #tCustomFormula (customformula_id int, customfunction varchar(50), customparameters varchar(100)) INSERT INTO #tCustomFormula(customformula_id, customfunction,

我有一个带有自定义函数(函数名和参数列表)的表,并使用它计算产品成本的百分比。我需要做的是SQL(SQLServer2008)

这是存储自定义函数的表

CREATE TABLE #tCustomFormula (customformula_id int, customfunction varchar(50), customparameters varchar(100))

INSERT INTO #tCustomFormula(customformula_id, customfunction, customparameters)
SELECT  1, 'xpCalcPercentage', 'customer_id,product_id,costperiod,productdate'
-- xpCalcPercentage is custom formula to calculate cost of a product
DROP TABLE #tCustomFormula
计算是在存储过程中完成的,在存储过程中,使用提供给存储函数的customformula_id和参数列表查询此表

例如:

exec spExecCustomFormula 
   1,   -- custom formula id from the table above
  '1,22,888,''2015-01-01''' -- parameters
或者,匹配表中的参数列表

exec spExecCustomFormula 
   1,   -- custom formula id from the table above
  'customer_id=1,product_id=22,costperiod=888,productdate=''2015-01-01'''  -- parameters
定义此存储过程的最佳方法是什么?基本上,我需要将存储过程的参数列表与表#tCustomFormula中的customparameters字段相匹配,构造executeSQL字符串,并使用动态SQL执行它

非常感谢您的帮助

谢谢, 吉娜


==================================================================================

两者都不是特别好,因为您需要将字符串解析为一组值,而SQL并不擅长这一点

您似乎在询问您尝试的解决方案,而不是问题本身,即。你能补充一些关于全局的信息吗?你为什么一开始就这么做