【问题标题】:Using sets as inparameters to function/sproc in SQL Server 2008?在 SQL Server 2008 中使用集合作为函数/存储过程的参数?
【发布时间】:2009-12-28 11:08:03
【问题描述】:

是否可以在 SQL Server 2008 中使用一个集合,例如 (1, 2, 3, 4, 5) 作为 Sproc、函数或视图的参数?

对于这个 SLQ,我应该使用 Sproc、函数还是视图?

WITH Scores AS(
    SELECT
        ItemId, SUM(Score) AS Score

    FROM [Presenta].[presenta].[LpivScores]

    WHERE
        // HERE I want (1, 2, 3, 4, 5) to be the inparameter, like @inParam
        ListPropertyItemId IN (1, 2, 3, 4, 5)

    GROUP BY
        ItemId
)

-- I want this to be returned
SELECT
    i.Id,
    s.Score
FROM
    Scores s,
    Items i
WHERE
    s.ItemId = i.Id

非常感谢任何帮助!

【问题讨论】:

    标签: sql sql-server sql-server-2008 stored-procedures views


    【解决方案1】:

    你可能想看看Table Valued Parameters

    【讨论】:

      【解决方案2】:
      【解决方案3】:

      这里还有一些技术可以查看分开的表值参数。

      您可以继续使用逗号分隔值,但您需要创建一个函数来拆分这些逗号分隔值。 http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm

      其他方法是使用 XML 参数。 http://weblogs.asp.net/jgalloway/archive/2007/02/16/passing-lists-to-sql-server-2005-with-xml-parameters.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-11
        • 2012-07-11
        • 2011-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多