Results 1 to 7 of 7

Thread: sum of 1+2+3

  1. #1
    Join Date
    Aug 2009
    Posts
    37

    Unanswered: sum of 1+2+3

    declare @str='1+2+3'

    i want sum of that 1+2+3

    can i get

    thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i think you should ask this guy
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    SELECT 1 + 2 + 3 As result



    If you want a different answer then ask a proper question: http://www.dbforums.com/microsoft-sq...ml#post4527530
    George
    Home | Blog

  4. #4
    Join Date
    Aug 2009
    Posts
    37
    hi
    declare @str varcahr(10)
    set @str='1+2+3'

    how to split them and how to add them

    thanks

  5. #5
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    1. create a loop
    2. parse the valid integers into a temp table column
    3. sun the columns

    Learn how to fish. Read BOL.

    -- This is all just a Figment of my Imagination --

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Why are you declaring a string of "numbers" in the first place?

    Wouldn't starting with numbers be a better way to go?
    Code:
    DECLARE @a int
         , @b int
         , @c int
    
    SELECT @a = 1
         , @b = 2
         , @c = 3
    
    SELECT @a + @b + @c As result
    George
    Home | Blog

  7. #7
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Using the integer datatype might not have been part of the assignment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •