|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, September 28, 2010 9:08 AM
Points: 15,
Visits: 122
|
|
Gurus I am at my wits end. I cant find anything online to help resolve this error and its probably something so simple. Your help is greatly appreciated.
This is running from sql2005 and inserting into sql2008 The error I am receiving is Insert Error: Column name or number of supplied values does not match table definition.
table:
CREATE TABLE [M].[tablename]( [column1] [int] IDENTITY(1,1) NOT NULL, [column2] [int] NULL, [column3] [varchar](50) NULL, [column4] [datetime] NULL, [column5] [date] NOT NULL ) ON [PRIMARY]
Query:
--SET IDENTITY_INSERT server.[M].[tablename] ON insert into opendatasource ('SQLNCLI', 'Data Source=REMOTESERVER;USER ID = User; PASSWORD=User') .server.[M].[tablename] VALUES ('column2', 'column3' ,GETDATE(),'column5')
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
| One thing that jumps out at me is that column5 is defined as a date, but your script tries to insert a string ('column5') there that cannot be converted to that type.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, September 28, 2010 9:08 AM
Points: 15,
Visits: 122
|
|
| I have code that will do the convert. but i didnt add it to the post :)
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
I just took a closer look at the code and realize that the insert doesn't specify the column names.
Try adding the list of columns right before the VALUES clause
insert into opendatasource ('SQLNCLI', 'Data Source=REMOTESERVER;USER ID = User; PASSWORD=User') .server.[M].[tablename] (Column2, column3, column4, column5) -- Column names in same order as VALUES clause VALUES ('column2', 'column3' ,GETDATE(),'column5')
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 9:57 PM
Points: 32,906,
Visits: 26,790
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, September 28, 2010 9:08 AM
Points: 15,
Visits: 122
|
|
| Yep that worked thanks :) I knew I was missing something simple
|
|
|
|