Error in inserting multiple records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akhush
    New Member
    • Nov 2011
    • 4

    Error in inserting multiple records

    Hi,
    I am getting error as below while inserting multiple records in table

    Code : INSERT INTO Management.Depa rtments(Departm entCode, Name)
    VALUES(N'ITEC', N'Information Technology'),
    (N'PRSN', N'Personnel');

    Error code : Msg 102, Level 15, State 1, Line 3 Incorrect syntax near ','.

    My MS SQL server version is:-
    Microsoft SQL Server 2005 - 9.00.5000.00 (Intel X86)
    Dec 10 2010 10:56:29
    Copyright (c) 1988-2005 Microsoft Corporation
    Express Edition on Windows NT 6.1 (Build 7601: Service Pack 1)

    compatibility level 90
    Please help me that why I am not able to insert multiple records and how this problem can be solved?
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Try removing those Ns

    Happy Coding!!!


    ~~ CK

    Comment

    • akhush
      New Member
      • Nov 2011
      • 4

      #3
      Hi,

      Thanks for replying me. However the checked by removing Ns still it is not working.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Don't think you can insert multiple records that way.

        Comment

        • akhush
          New Member
          • Nov 2011
          • 4

          #5
          Hi,

          No I am able to insert multiple records as I mentioned earlier...

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            No... you said you're getting an error trying to insert multiple records using that syntax. You didn't say you were able to insert multiple records. Otherwise, you have no question.

            Comment

            • ck9663
              Recognized Expert Specialist
              • Jun 2007
              • 2878

              #7
              Oooppss, sorry I missed that. I don't think you can insert rows that way. If you want you can use UNION ALL to combined those two rows that you are trying to insert.

              Happy Coding!!!


              ~~ CK

              Comment

              • akhush
                New Member
                • Nov 2011
                • 4

                #8
                Sorry i missed "not" in my last conversation... I am not able to insert records through the query i mentioned above.
                Even i tried union all in last it did not worked.

                Comment

                • Maraj
                  New Member
                  • Nov 2011
                  • 24

                  #9
                  Try like this it will work if your data types are char or varchar for both columns.

                  INSERT INTO Management.Depa rtments(Departm entCode, Name)
                  VALUES('ITEC', 'Information Technology'),
                  ('PRSN', 'Personnel')

                  Comment

                  • ck9663
                    Recognized Expert Specialist
                    • Jun 2007
                    • 2878

                    #10
                    You can either do two insert statements, or do a UNION ALL. Can you post the UNION ALL code that you did so we can see why it failed?


                    ~~ CK

                    Comment

                    Working...