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 6744133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:02:50+00:00 2026-05-26T12:02:50+00:00

My requirement is to send Columnname as Parameter to Stored procedure and do SUM

  • 0

My requirement is to send Columnname as Parameter to Stored procedure and do SUM on that Column.

I have written a small stored procedure to accept the column name as a parameter and do sum on that but I am getting an error with it.

CREATE PROCEDURE dbo.testCol
    -- Add the parameters for the stored procedure here
    @type as nvarchar(20),
    @beginDate as smalldatetime,
    @endDate as smalldatetime
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here


        select dbo.mytable.date, sum(@type) as quantity 
        from dbo.mytable
            where dbo.mytable.Date between @beginDate AND @endDate
        group by dbo.mytable.date,dbo.mytable.day 
        order by dbo.mytable.date
END
GO

I am getting the error as "Operand data type nvarchar is invalid for sum operator." while executing this stored procedure.

Any help much appreciated.

Thanks

  • 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-26T12:02:50+00:00Added an answer on May 26, 2026 at 12:02 pm

    You’ll need to use dynamic sql to get the passed column name to be used this way in the query.

    Use sp_executesql and include the column name in the string, and pass @beginDate and @endDate as parameters.

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

Sidebar

Related Questions

I have a requirement to send data from native program written in C through
I have a requirement to send some 100 bytes data over internet .My machine
I have a requirement to send the results of a query in emails. I
I have a requirement to parse a huge text file and send parts of
I have a requirement in my application that I think can be met by
I have a requirement that , I want to do some changes in my
My Requirement is whenever I click on the Extension Icon that should send a
Hi i have following requirement. 1) A website will send a get request with
I have the requirement that whenever there is a model get's added/changed/deleted, it should
I have currently written code to send an email in C# using the usual

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.