2

I know this may be simple to some but Im having a hard time with this. I simply want to add two columns together. My first number is "FirstShift" = 90, "SecondShift" = 100. Why am I not getting 190? I should see my 23 records all with different values 190 being my top record.

SELECT
    [FirstShift] + [SecondShift] AS [Total Counted]
FROM

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Frater
  • 47
  • 1
  • 2
  • 8

2 Answers2

5

If those aren't numeric fields, you are going to have to fix your schema, or cast them as numeric fields.

If you don't want to fix your schema, try changing your query to this.

SELECT
    CAST([FirstShift] AS DECIMAL) + CAST([SecondShift] AS DECIMAL) AS [Total Counted]
FROM
Adam Scharp
  • 632
  • 5
  • 18
3

Ok... "really" Do both the table columns representing [FirstShift] and [SecondShift] have a numeric datatype?

I know its been asked but did you really mean what you said?

The "+" operator will act as a "concatenator" if either of the fields is a string. If both fields are numeric it will act as a "sum" operation...

Table [A]
[FirstShift] VARCHAR(10)    holds value "90"
[SecondShift] VARCHAR(10)   holds value "100"

[FirstShift] + [SecondShift] ==>  "90100"

WHEREAS

Table [A]
[FirstShift] INTEGER(10)    holds value 90
[SecondShift] INTEGER(10)   holds value 100

[FirstShift] + [SecondShift] ==>  190
ThePuss
  • 61
  • 3