开发者

sql insert into values The multi-part identifier could not be bound

I am trying to run this command which shoulld append 80 rows.. but i get.

Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "Frame.Guid" could not be bound.

 INSERT  INTO  studentrecords(recordGuid, studentGuid, courseGuid, licenseGuid, repeatflag, frameGuid, coredata, framescore, timeinframe, locked, daterefreshed, dateinserted)
 VALUES     (NEWID(), '25d6e1d9-e5ce-42dd-bd6a-开发者_如何转开发5956ec7cb047', '54dffd58-1af9-44cf-982e-ea0e8930878e', '00000000-1111-1111-0000-000000000000', 0, Frame.Guid,  '<flags><flag1>1</flag1> <flag2>1</flag2> <flag3>1</flag3> <flag4>1</flag4> <flag5>1</flag5><flag6>1</flag6></flags><StudentAnswer> <CorrectionHistory></CorrectionHistory> </StudentAnswer>', 0, 55860, 1, GETDATE(), GETDATE())
 Select Frame.Guid FROM Frame
 WHERE  (Frame.Course = '54dffd58-1af9-44cf-982e-ea0e8930878e') AND (Frame.Template <> '7d3a3b40-86e3-43f4-a4ca-039afdd0b7a3')


INSERT INTO studentrecords (
                            recordGuid, studentGuid, courseGuid, licenseGuid, 
                            repeatflag, frameGuid, coredata, 
                            framescore, timeinframe, locked, 
                            daterefreshed, dateinserted
                           ) 
   SELECT NEWID(), 
          '25d6e1d9-e5ce-42dd-bd6a-5956ec7cb047', 
          '54dffd58-1af9-44cf-982e-ea0e8930878e', 
          '00000000-1111-1111-0000-000000000000', 
          0, Frame.Guid, '1 1 1 1 11 ', 0, 55860, 1, 
          GETDATE(), GETDATE() 
     FROM Frame 
    WHERE Frame.Course = '54dffd58-1af9-44cf-982e-ea0e8930878e'
          AND Frame.Template <> '7d3a3b40-86e3-43f4-a4ca-039afdd0b7a3';


I can't see how you want the "insert" and "select" queries here to be related -- they're both syntactically complete but not linked in any way. You're expecting "Frame.Guid" in the first query to come from the second query, somehow, but I can't quite get how. In any case, that's all that the error message is saying; it can't tell what you mean by Frame.Guid, exactly.


You're referencing Frame.Guid in the insert statement, but there isn't one defined. I suspect you want to select that value into a variable, then use the variable in the insert statement.

DECLARE @frameGUID GUID

SET @frameGUID = (Select Frame.Guid FROM Frame
WHERE  (Frame.Course = '54dffd58-1af9-44cf-982e-ea0e8930878e')
   AND (Frame.Template <> '7d3a3b40-86e3-43f4-a4ca-039afdd0b7a3'))

INSERT  INTO  studentrecords(recordGuid, studentGuid, courseGuid, licenseGuid, repeatflag, frameGuid, coredata, framescore, timeinframe, locked, daterefreshed, dateinserted)
VALUES  (
    NEWID(),
    '25d6e1d9-e5ce-42dd-bd6a-5956ec7cb047',
    '54dffd58-1af9-44cf-982e-ea0e8930878e',
    '00000000-1111-1111-0000-000000000000',
    0,
    @frameGUID,
    '<flags><flag1>1</flag1> <flag2>1</flag2> <flag3>1</flag3> <flag4>1</flag4> <flag5>1</flag5><flag6>1</flag6></flags><StudentAnswer> <CorrectionHistory></CorrectionHistory> </StudentAnswer>',
    0,
    55860,
    1,
    GETDATE(),
    GETDATE())


You have two statements there. The INSERT statement has no way of knowing that you want the field Frame.Guid out of the SELECT statement.

You need to refactor it into one statement. You can do that by putting all the constants into the SELECT statement (between SELECT and FROM) and deleting the VALUES clause. Then it will be one statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜