Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


identity column using opendatasource


identity column using opendatasource

Author
Message
NewbieCoding
NewbieCoding
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 154
Gurus I am at my wits end.w00t 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')
john.arnott
john.arnott
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1536 Visits: 3059
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.
NewbieCoding
NewbieCoding
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 154
I have code that will do the convert. but i didnt add it to the post Smile
john.arnott
john.arnott
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1536 Visits: 3059
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')



Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)

Group: General Forum Members
Points: 51981 Visits: 40313
BWAA-HAA! Finally! I read a whole post before jumping in! :-D 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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
NewbieCoding
NewbieCoding
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 154
Yep that worked thanks Smile I knew I was missing something simple
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search