0

下面的 sql 语句(没有 if)返回 1 行,1 列 = 8。但是如果我在 SELECT 和 <. 我想要做的是,如果返回的测试为 true 的行数少于 50。如果返回 50 行,则返回 false。

谢谢您的帮助

IF SELECT COUNT([VDeck_ID]) FROM [SecondLifeDatabases].[dbo].[YuGiOh-Cards]
    WHERE [User_ID] = 
            (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-Users] 
            WHERE [UUID] = 'D38C3475-C995-4EB2-85D0-F2A3ED1D23A0') 
                and [VDeck_ID] = 
                    (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-VDecks]
                        WHERE [DeckName] = 'NewDeckName')
    < 50
BEGIN
    UPDATE [SecondLifeDatabases].[dbo].[YuGiOh-Cards] 
    SET [VDeck_ID] = 
        (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-VDecks] 
        WHERE [User_ID] = 
            (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-Users] 
            WHERE [UUID] = 'D38C3475-C995-4EB2-85D0-F2A3ED1D23A0') 
                and [DeckName] = 'NewDeckName') 
                WHERE [ID] = '11'
END
4

2 回答 2

2

select在子句中的语句周围加上括号if

IF (SELECT COUNT([VDeck_ID]) FROM [SecondLifeDatabases].[dbo].[YuGiOh-Cards]
    WHERE [User_ID] = 
            (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-Users] 
            WHERE [UUID] = 'D38C3475-C995-4EB2-85D0-F2A3ED1D23A0') 
                and [VDeck_ID] = 
                    (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-VDecks]
                        WHERE [DeckName] = 'NewDeckName')
   )
    < 50
BEGIN
    UPDATE [SecondLifeDatabases].[dbo].[YuGiOh-Cards] 
    SET [VDeck_ID] = 
        (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-VDecks] 
        WHERE [User_ID] = 
            (SELECT [ID] FROM [SecondLifeDatabases].[dbo].[YuGiOh-Users] 
            WHERE [UUID] = 'D38C3475-C995-4EB2-85D0-F2A3ED1D23A0') 
                and [DeckName] = 'NewDeckName') 
                WHERE [ID] = '11'
END
于 2013-01-15T17:06:19.193 回答
0

你需要括号...

IF (SELECT COUNT(..) FROM ...) > 50
于 2013-01-15T17:06:17.833 回答