我试图从子查询中选择多个变量,以便以后使用。这是我的代码:

DECLARE @MarketplaceName VARCHAR(50),
    @ProductFieldID INT,
    @FromValue VARCHAR(255) = (
        SELECT mcvm.MarketplaceName,
            mcvm.ProductFieldID,
            mcvm.FromValue
        FROM [Meta].[MarketplaceCategoryValueMapping] AS mcvm
        WHERE mcvm.MarketplaceCategoryValueMappingID = @MapID
        )


我收到以下错误消息:


如果未使用EXISTS引入子查询,则只能在选择列表中指定一个表达式。


我正在尝试从@MarketplaceName等映射mcvm.MarketplaceName

我想不必为每个这些变量编写多个SELECT语句。

最佳答案

您是否正在尝试这样做?

DECLARE @MarketplaceName VARCHAR(50),
        @ProductFieldID INT,
        @FromValue VARCHAR(255)
SELECT  @MarketplaceName    = mcvm.MarketplaceName,
        @ProductFieldID     = mcvm.ProductFieldID,
        @FromValue          = mcvm.FromValue
FROM [Meta].[MarketplaceCategoryValueMapping] AS mcvm
WHERE mcvm.MarketplaceCategoryValueMappingID = @MapID

关于sql - 如何在T-SQL中分配多个内联变量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14245738/

10-08 23:49