1

私は2つのテーブルを持っています:

CREATE TABLE [Training].[UserTrainingModuleResults](
[UserTrainingModuleResultId] [int] IDENTITY(1,1) NOT NULL,
[TrainingModules_TrainingModuleId] [int] NOT NULL,
[Users_UserId] [int] NOT NULL,
[DateAndTimeStarted] [datetime] NOT NULL,
[DateAndTimeCompleted] [datetime] NULL,
[NumberOfQuestionsAnswered] [smallint] NOT NULL,
[NumberOfQuestionsAnsweredCorrectly] [smallint] NOT NULL,
[TrainingModuleStatuses_TrainingModuleStatusId] [smallint] NOT NULL,
  CONSTRAINT [PK_UserTrainingModuleResults] PRIMARY KEY CLUSTERED 
(
[UserTrainingModuleResultId] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,    ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [History].[ViewTrainingModuleHistory](
[HistoryId] [int] NOT NULL,
[TrainingModules_TrainingModuleId] [int] NOT NULL,
CONSTRAINT [PK_ViewTrainingModuleHistory] PRIMARY KEY CLUSTERED 
(
[HistoryId] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
 ) ON [PRIMARY]

次に、TrainingModules_TrainingModuleId = UserTrainingModuleResults.TrainingModules_TrainingModuleId の ViewTrainingModuleHistory から削除する必要があるスクリプトがあります。

delete from History.TrainingModuleCompletedHistory as tmch  //syntax error here
  left join Training.UserTrainingModuleResults as utmr
on utmr.UserTrainingModuleResultId = tmch.UserTrainingModuleResults_UserTrainingModuleResultId
where utmr.Users_UserId = 446 and tmch.UserTrainingModuleResults_UserTrainingModuleResultId = 110

上記は正しくありません。「as」の近くで構文エラーが発生します。助けてください

4

3 に答える 3

0

エイリアスは単語の直後にある必要がありますDELETE:

delete tmch   --- < alias of table to delete records from goes here
from History.TrainingModuleCompletedHistory tmch  
left join Training.UserTrainingModuleResults utmr
  on utmr.UserTrainingModuleResultId = tmch.UserTrainingModuleResults_UserTrainingModuleResultId
where utmr.Users_UserId = 446 
  and tmch.UserTrainingModuleResults_UserTrainingModuleResultId = 110
于 2012-11-21T10:48:07.437 に答える
0
delete tmch  
from History.TrainingModuleCompletedHistory tmch  
left join Training.UserTrainingModuleResults utmr
on utmr.UserTrainingModuleResultId = tmch.UserTrainingModuleResults_UserTrainingModuleResultId
where utmr.Users_UserId = 446 
and tmch.UserTrainingModuleResults_UserTrainingModuleResultId = 110
于 2012-11-21T10:48:15.367 に答える