SQL Server Performance

add 2 fields from table

Discussion in 'General Developer Questions' started by d17may, Nov 2, 2006.

  1. d17may New Member

    I have table which has say field1,field2.I want that when i execute a query
    it gives me the sum of 2 fields .Both fields are nvarchar.
    Thanks
  2. FrankKalis Moderator


    SELECT ISNULL(field1,0)+ISNULL(field2,0)
    FROM table;


    --
    Frank Kalis
    Moderator
    Microsoft SQL Server MVP
    Webmaster:http://www.insidesql.de
  3. Roji. P. Thomas New Member

  4. Madhivanan Moderator

    quote:Originally posted by d17may

    I have table which has say field1,field2.I want that when i execute a query
    it gives me the sum of 2 fields .Both fields are nvarchar.
    Thanks
    If they are numbers, then why did you use nvarchar?
    Use proper datatype to avoid unnecessary conversion

    Madhivanan

    Failing to plan is Planning to fail
  5. Madhivanan Moderator

    quote:Originally posted by Roji. P. Thomas

    SELECT SUM(CAST(fld1 AS NUMERIC(18,2))) + SUM(CAST(fld2 AS NUMERIC(18,2)))
    FROM YourTab

    Roji. P. Thomas
    http://toponewithties.blogspot.com

    Provided that there are no alphabets or other characters

    Madhivanan

    Failing to plan is Planning to fail

Share This Page