Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

identity column using opendatasource Expand / Collapse
Author
Message
Posted Tuesday, January 19, 2010 12:06 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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')

Post #850014
Posted Tuesday, January 19, 2010 1:21 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, April 27, 2014 6:26 AM
Points: 1,521, Visits: 3,036
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.
Post #850093
Posted Tuesday, January 19, 2010 1:38 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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 :)
Post #850105
Posted Tuesday, January 19, 2010 2:47 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, April 27, 2014 6:26 AM
Points: 1,521, Visits: 3,036
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')


Post #850126
Posted Tuesday, January 19, 2010 8:33 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:52 PM
Points: 36,773, Visits: 31,229
BWAA-HAA! Finally! I read a whole post before jumping in! Nicely done, John.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #850191
Posted Wednesday, January 20, 2010 8:04 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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
Post #850513
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse