SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


insert into table execution of a stored procedure


insert into table execution of a stored procedure

Author
Message
bkshn
bkshn
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 125
Hello
I have this table
declare @UserMidListTable Table (Id Int,Mid int,ValueMid int,CatParent int, [Enabled] int,LastUpdate Datetime,Company nvarchar(max))

I want to fill it with the execution of this stored procedure

insert into @UserMidListTable (Id ,Mid ,ValueMid ,CatParent , [Enabled] ,LastUpdate ,Company)
exec UserMidList @userRkey,'20','0','0','10','1','2','',''

the execution of stored procedure is bellow

id Mid ValueMid CatParent Enabled LastUpdate company
1 20 100001 NULL 25 NULL NULL
2 20 100007 NULL 25 NULL NULL
3 20 100030 NULL 25 NULL NULL
4 20 100042 NULL 25 NULL NULL
5 20 100043 NULL 25 NULL NULL

BUT I see this error

Column name or number of supplied values does not match table definition.

I don't know what is wrong.
samulasudharshan
samulasudharshan
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 1
SQL Server Version?
bkshn
bkshn
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 125
sql server 2008 R2
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)

Group: General Forum Members
Points: 378192 Visits: 42930
Is your server case sensitive by any chance? Also, what is the compatibility level for the database set to?

--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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
samulasudharshan
samulasudharshan
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 1
Are the datatypes of the output columns from stored procedure same as the Table Variable?
bkshn
bkshn
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 125
Yes they are same
kapil_kk
kapil_kk
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8299 Visits: 2777
can you please provide definition of your sql procedure

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
harsha.majety
harsha.majety
SSC-Addicted
SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)

Group: General Forum Members
Points: 469 Visits: 449
I ran following on sql server 2008 r2 with no errors . you prbly need to check your sproc definition.

if exists(select * from sys.objects (nolock) where name = 'UserMidList' and type = 'P')
begin
exec('drop proc UserMidList');

end
go
create proc UserMidList as

select 1, 20, 100001, NULL, 25, NULL, NULL
union
select 2, 20, 100007, NULL, 25, NULL, NULL
union
select 3, 20, 100030, NULL, 25, NULL, NULL
union
select 4, 20, 100042, NULL, 25, NULL, NULL
union
select 5, 20, 100043, NULL, 25, NULL, NULL



go

declare @UserMidListTable Table (Id Int,Mid int,ValueMid int,CatParent int, [Enabled] int,LastUpdate Datetime,Company nvarchar(max))

insert into @UserMidListTable (Id ,Mid ,ValueMid ,CatParent , [Enabled] ,LastUpdate ,Company)
exec UserMidList

select * from @UserMidListTable
go

select @@version
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
--Jun 17 2011 00:54:03
--Copyright (c) Microsoft Corporation
--Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
Andy Steinke
Andy Steinke
SSC Veteran
SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)

Group: General Forum Members
Points: 255 Visits: 702
You could use OPENROWSET to create a temporary table (example and link to example web page below) and check that the stored procedure definition matches your table variable definition.


SELECT * into #Temp2
FROM OPENROWSET ('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','set fmtonly off exec master.dbo.sp_who2')


From http://blogs.technet.com/b/wardpond/archive/2005/08/01/the-openrowset-trick-accessing-stored-procedure-output-in-a-select-statement.aspx
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)SSC Guru (378K reputation)

Group: General Forum Members
Points: 378192 Visits: 42930
The problem with using OPENROWSET is that it requires "SA" privs. That's ok for jobs but should not be ok for application logins.

--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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
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