Storing formula (equations) in database to be evaluated later (SQL Server 2005)

前端 未结 4 1021
[愿得一人]
[愿得一人] 2020-12-10 20:09

I\'m calculating linear regressions based on a data set. I do not know the regression model or number of parameters at compile-time.

I\'m storing the regression equa

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 20:59

    In Sql Server, something like this Select 2+2 would return 4. So, you could have a stored procedure that reads the string out of the database and then builds another dynamic string let's call it (@SQLString) and run that query.

    For example in this case the formula could be x + 2, then you build up a dynamic string based on that, and then call sp_executesql:

    EXEC sp_executesql @SQLString
    

    However, you should read this article on Dynamic SQL before you go down that road.

    I believe what you are doing it just fine.

提交回复
热议问题