下面的sql语句(没有if)返回1行,1列= 8.但是如果我在SELECT和on<上得到语法错误。我试图做的是,如果少于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
答案 0 :(得分: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
答案 1 :(得分:0)
你需要括号......
IF (SELECT COUNT(..) FROM ...) > 50