Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:05:38+00:00 2026-05-26T09:05:38+00:00

In Sql server, i write a procedure and i use one tem table and

  • 0

In Sql server, i write a procedure and i use one tem table and a cursor and dynamically add one column to that temporary table but it is giving erro :

(10 row(s) affected)
Msg 213, Level 16, State 1, Procedure USP_F_Roll_AllIndia_Report, Line 27
Column name or number of supplied values does not match table definition.

This is my proc :

alter procedure USP_F_Roll_AllIndia_Report       
(@segcode int,@rollplanyear int)
as
 begin
declare @cfcode varchar(10)
declare @cfname varchar(30)
declare @SQl nvarchar(max)  

create table #TEP (productcode varchar(10) collate database_default,proddesc varchar(100))

declare db_cursor cursor for   

select distinct canfm.CFCode, SUBSTRING (CANFM.CFName,4,5)as CFName   from Tbl_F_CandF_M CANFM left outer join   Tbl_F_Org_CandF_T CT  on  CANFM.CFCode = ct.CFCode where  CANFM .status =1 and ct.Status =1 order by canfm.cfcode   

open db_cursor 

fetch next from db_cursor into @cfcode, @cfname

while @@FETCH_STATUS =0
  begin

    set @SQL ='alter table #TEP add '+@cfname+' float'  
    exec sp_executesql @Sql
    --exec  ( @Sql)


    insert into #TEP 

    select pd.productcode,PM.productdesc,convert(varchar,sum(isnull(AmendedQty,isnull(Quantity,0))))as quantity    from Tbl_F_Roll_PlanDetails_T pd left outer join Tbl_F_ProductMaster_M PM on
    pd.ProductCode =pm.ProductCode left outer join Tbl_F_CandF_M CANDF on pd.CandFLocation =CANDF.CFCode    where pd. RollPlanYear =@rollplanyear and pd.CandFLocation =@cfcode  and  pd.ProductCode in (
    select ProductCode  from   Tbl_F_Segment_Product_t where SegCode  =@segcode )    group by pd.ProductCode,pm.ProductDesc  

   fetch next from db_cursor into @cfcode, @cfname
 end              
     close db_cursor              
     deallocate db_cursor                                             
     select * from #TEP               
 end  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:05:38+00:00Added an answer on May 26, 2026 at 9:05 am

    this will not work . if you are adding column then your select query in insert statement must be a dynamic one since it will keep adding column .

    you can create a dynamic query for insert and in select as well.
    you will also need to specify columns names like
    insert into #TEP (col1,clo2,col3..)

    there might be better ways for your requiremnet if you specify them .
    cursor and adding column is not good logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would one write a sql server DDL script that can: For each table
I need to write a Stored procedure in SQL server whose data returned will
I have to write a component that re-creates SQL Server tables (structure and data)
I am using the AdoNetAppender to write to a SQL Server 2005 database table.
Using SQL Server 2008 Reporting services: I'm trying to write a report that displays
I'm trying to use a SQL Server stored procedure with ASP: ALTER PROCEDURE [dbo].[user_insert]
I am trying to write a Stored Procedure in SQL Server (2005) to do
I write the following stored procedure in sql server 2008 i am getting the
Below is pseudo-code for SQL Server stored procedure I need to write: int[] followers
I want to write a SQL Server 2005 stored procedure which will select and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.