1

I am running a query just a simple Select Statement, how can I append (from within the query) a value to my int column? I have tried the below, but keep getting this error: Msg 245, Level 16, State 1, Line 1 Syntax error converting the varchar value 'Month ' to a column of data type int.

SELECT a.Sales, SUM(a.Count) As Count, CONVERT(INT, 'Month ') + dt.CumulativeMonth
FROM Rep a
INNER JOIN Date dt
ON a.Date = dt.FD
GROUP BY dt.CumulativeMonth, a.Sales
3
  • 2
    Addition / math has priority over string concatenation. To make it clear to SQL Server that you want to join strings, not add, you should convert the month to a string, e.g. CONVERT(VARCHAR(2), dt.CumulativeMonth). Not sure why you are trying to convert 'Month ' to an integer. How does that work exactly? Commented Feb 10, 2014 at 16:42
  • I just want to append the text Month to the beginning of a numeric month value. I can't modify the table so thought I would just do it from within the Select statement. Commented Feb 10, 2014 at 16:44
  • @Shiva yes, apology for my mistake there. Commented Feb 10, 2014 at 16:46

1 Answer 1

3

Here you go.

SELECT a.Sales, SUM(a.Count) As Count, 'Month ' + CONVERT(VARCHAR(20), dt.CumulativeMonth)
FROM Rep a
INNER JOIN Date dt
ON a.Date = dt.FD
GROUP BY dt.CumulativeMonth, a.Sales
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.