0

T-SQLを使用して作成したBeersというテーブルに7種類のビールを挿入しようとしています。VALUESでエラーが発生し続けますが、次のメッセージが表示されます。

クエリの実行中に次のエラーが発生しました。

Server: Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'. 
Incorrect syntax near the keyword 'VALUES'.

足りないものはありますか?エラーが何であるかわかりません。

これが私のSQLです

-データベースにビールを追加

SET IDENTITY_INSERT [dbo].[Beers] ON

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 1)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType],    [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (1, 'Black_Butte', '$9.00', 'porter', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 2)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType],  [BeerRating],  [Enabled], [DateInserted],[DateLastActivity],
 VALUES (2, 'Corona', '$5.00', 'lager', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 3)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (3, 'Duvel', '$12.00', 'pale ale', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 4)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (4, 'Guinness', '$7.00', 'stout', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 5)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (5, 'Heineken', '$6.00', 'lager', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 6)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (6, 'Pilsner_Urquell', '$6.50', 'pilsner', NULL, 1, '20071111', '20071111')

IF NOT EXISTS (SELECT [BeerId] FROM [dbo].[Beers] WHERE [BeerId] = 7)
 INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity],
 VALUES (7, 'Stone', '$10.00', 'IPA', NULL, 1, '20071111', '20071111')


SET IDENTITY_INSERT [dbo].[Beers] OFF
4

3 に答える 3

0

VALUESの前に閉じ括弧がありません。

INSERT INTO [dbo].[Beers] ([BeerId], [BeerName], [BeerPricePerBottle], [BeerType], [BeerRating], [Enabled], [DateInserted],[DateLastActivity]) VALUES 
于 2013-03-26T10:06:48.780 に答える
0

閉じ括弧がなく、すべてのINSERTステートメントの最後に余分なコンマが追加されています...

以下のように変更すると、機能しますが、

から

,[DateLastActivity],
 VALUES (1, 'Black_Butte', '$9.00', 'porter', NULL, 1, '20071111', '20071111')

,[DateLastActivity])
 VALUES (1, 'Black_Butte', '$9.00', 'porter', NULL, 1, '20071111', '20071111')
于 2013-03-26T10:08:46.477 に答える
0

これを試して:

IF NOT EXISTS(SELECT [BeerId]FROM[dbo]。[Beers]WHERE[BeerId] = 1)INSERT INTO([dbo]。[Beers]([BeerId]、[BeerName]、[BeerPricePerBottle]、[BeerType]、 [BeerRating]、[Enabled]、[DateInserted]、[DateLastActivity])VALUES(1、'Black_Butte'、'$ 9.00'、'porter'、NULL、1、 '20071111'、 '20071111')

于 2013-03-26T10:31:13.390 に答える