Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Help Me:Can we select sum of 2 columns in one select statement?

Help Me:Can we select sum of 2 columns in one select statement?

Scheduled Pinned Locked Moved Database
databasehelpsharepointquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    priya_p233
    wrote on last edited by
    #1

    Good morning freinds, i m trying to create following procedure in mysql5.0 but getting error abt check syntax in sql statement on 2nd column i.e. at sum(Tuesday). Monday & Tuesday are two columns of which i wnt to display sum of all records of Monday & tuesday so i wrote following procedure but Error??:sigh: As I tried already, i selected sum of other 2 columns at a time in one select stmt, but it is also giving error at 2nd column. In simple query i can select sum of more than one columns but why not in procedure? Anybody please help me following is the my procedure.----> DELIMITER $$ DROP PROCEDURE IF EXISTS `timesheet`.`sp_select` $$ CREATE PROCEDURE `sp_select`() BEGIN DECLARE mon,tue double; SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; SELECT mon,tue; END $$ DELIMITER ; What should i change in it to run properly. Please Reply Soon.:sigh: Thanx. -Regards Priya.

    "The Difficult i can do it now... The Impossible will take a little longer."

    K A 2 Replies Last reply
    0
    • P priya_p233

      Good morning freinds, i m trying to create following procedure in mysql5.0 but getting error abt check syntax in sql statement on 2nd column i.e. at sum(Tuesday). Monday & Tuesday are two columns of which i wnt to display sum of all records of Monday & tuesday so i wrote following procedure but Error??:sigh: As I tried already, i selected sum of other 2 columns at a time in one select stmt, but it is also giving error at 2nd column. In simple query i can select sum of more than one columns but why not in procedure? Anybody please help me following is the my procedure.----> DELIMITER $$ DROP PROCEDURE IF EXISTS `timesheet`.`sp_select` $$ CREATE PROCEDURE `sp_select`() BEGIN DECLARE mon,tue double; SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; SELECT mon,tue; END $$ DELIMITER ; What should i change in it to run properly. Please Reply Soon.:sigh: Thanx. -Regards Priya.

      "The Difficult i can do it now... The Impossible will take a little longer."

      K Offline
      K Offline
      K P Kannan
      wrote on last edited by
      #2

      SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; I haven't run this query and tested May be this could be the reason: sum(Monday) into mon - variable mon has been assigned sum(Tuesday) as tue - It is pseudo column won't that be sum(Tuesday) into tue

      1 Reply Last reply
      0
      • P priya_p233

        Good morning freinds, i m trying to create following procedure in mysql5.0 but getting error abt check syntax in sql statement on 2nd column i.e. at sum(Tuesday). Monday & Tuesday are two columns of which i wnt to display sum of all records of Monday & tuesday so i wrote following procedure but Error??:sigh: As I tried already, i selected sum of other 2 columns at a time in one select stmt, but it is also giving error at 2nd column. In simple query i can select sum of more than one columns but why not in procedure? Anybody please help me following is the my procedure.----> DELIMITER $$ DROP PROCEDURE IF EXISTS `timesheet`.`sp_select` $$ CREATE PROCEDURE `sp_select`() BEGIN DECLARE mon,tue double; SELECT sum(Monday) into mon , sum(Tuesday) as tue FROM timesheet_nonbillables; SELECT mon,tue; END $$ DELIMITER ; What should i change in it to run properly. Please Reply Soon.:sigh: Thanx. -Regards Priya.

        "The Difficult i can do it now... The Impossible will take a little longer."

        A Offline
        A Offline
        asithangae
        wrote on last edited by
        #3

        hai priya, you have not added Group by keyword in that, is that may be problem? using aggregate functions without groupby may also create problems. change that and try... Cheers asithangae

        A 1 Reply Last reply
        0
        • A asithangae

          hai priya, you have not added Group by keyword in that, is that may be problem? using aggregate functions without groupby may also create problems. change that and try... Cheers asithangae

          A Offline
          A Offline
          asithangae
          wrote on last edited by
          #4

          hai, check this it works for you... declare @mon decimal declare @tue decimal select @mon = sum(ContactID), @tue = sum(ManagerID) from Employee select @mon,@tue cheers asithangae

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups