0

以下の SQL ステートメント (if なし) は、1 行、1 列 = 8 を返します。ただし、if を使用すると、SELECT および < で構文エラーが発生します。私がやろうとしているのは、50 行未満の行がテスト true を返した場合です。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 に答える