Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have follow function:
C#
Function [dbo].[FilterLedgerDocumentItemWithDateAndNumber] (
				@EnterpriseId uniqueidentifier,
				@FilterFromDate datetime2(7),
				@FilterToDate datetime2(7)
				
				)
				
RETURNS TABLE
AS
RETURN 
(Select CASE MONTH(ledger.CreateDate)
		When 1 then 'January'
		When 2 then 'February'
		When 3 then 'March'
		When 4 then 'April'
		When 5 then 'May'
		When 6 then 'June'
		When 7 then 'July'
		When 8 then 'August'
		When 9 then 'September'
		When 10 then 'October'
		When 11 then 'November'
		When 12 then 'December'
	End as MonthOfDocumentItem
	,case when Sum(ledger.Credit)>Sum(ledger.Debit)
			 then Sum(ledger.Credit)-Sum(ledger.Debit)
			 else 
			  Sum(ledger.Credit)-Sum(ledger.Debit)
			  	End as CredotDebit,ledger.AccountId,ledger.Title
		From GetLedgerDocumentItem(@EnterpriseId) as ledger
		Where	ledger.CreateDate >= @FilterFromDate And
				ledger.CreateDate <= @FilterToDate
				
				
		group by MONTH(ledger.CreateDate),ledger.AccountId,ledger.Title

		)

and i insert value of it to table:
C#
function [dbo].[SampleTr](@IsFilteDate bit,
						 @IsFilterDocumentNumber bit,
						 @EnterpriseId uniqueidentifier,
						 @FilterFromDate datetime2(7),
						 @FilterToDate datetime2(7)
						  
						) 
  returns @results table (
                          MonthOfDocumentItem datetime2(7),
						   AccountId nvarchar(50),
							CreditDebit decimal,
							Title nvarchar(150)
			 )
as
begin

		  if @IsFilteDate=1 and @IsFilterDocumentNumber = 1 
		  begin       
		   	insert @results (MonthOfDocumentItem,CreditDebit,AccountId,Title)
		    Select	asd.MonthOfDocumentItem,asd.CredotDebit,asd.AccountId,asd.Title
			From FilterLedgerDocumentItemWithDateAndNumber(@EnterpriseId,@FilterFromDate,@FilterToDate) as asd
		  end   
		  
		  return
end

error=&The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.
Posted
Updated 30-Oct-13 1:11am
v3

1 solution

It looks that your function is returning more than one columns .For that
1. Try To execute each small part on database with data
2. see where columns exceeds bec'se this error only bec'se column values increase than expected in insert command
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900