1

我正在尝试在 SQL Server 中使用以下查询

SELECT [AL].[Subscriptions].Id,
       [AL].[Subscriptions].name,
       [AL].[Subscriptions].description,
       [AL].[Subscriptions].price,
       [AL].[Subscriptions].iconFileName,
       IIf(a.expiryDate > Now(), 'TRUE', 'FALSE') AS isSubsByUser
FROM   [AL].[Subscriptions]
       LEFT JOIN (SELECT *
                  FROM   [AL].[UserSubscriptions]
                  WHERE  userId = 13259) AS a
         ON Subscriptions.Id = a.itemid; 

但总是得到错误

函数参数列表中的错误:“>”无法识别。无法解析查询文本。

我该如何解决?

4

1 回答 1

0

就像马丁史密斯说的,你需要使用案例陈述。此外,您似乎只在派生表中使用了几个字段,因此我建议不要使用 *. 我在下面举了一个例子。

   SELECT [AL].[Subscriptions].Id,
        [AL].[Subscriptions].name,
        [AL].[Subscriptions].description,
        [AL].[Subscriptions].price,
        [AL].[Subscriptions].iconFileName,
        case when a.expiryDate > GetDate() then 'TRUE' else 'FALSE' end AS isSubsByUser
   FROM   [AL].[Subscriptions]
   LEFT JOIN (SELECT expiryDate, itemid 
              FROM   [AL].[UserSubscriptions]
              WHERE  userId = 13259) AS a
     ON Subscriptions.Id = a.itemid; 
于 2012-11-23T18:44:30.873 回答