Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Robin Burgess4,110 Points
Concatenation vs. Addition in MS SQL?
I am currently taking my SQL baby steps in hopes that I can apply the knowledge at work. We use Microsoft SQL at work, and the Teacher's Notes in "Adding Text Columns Together" in the Reporting course mentions that + is the concatenation operator in MS SQL.
Though I haven't bumped into this yet, I am curious-- how does one differentiate this from addition? To use the example presented by one of the lessons, if I wanted to add a processing fee (say, 10.80) to the base cost (say, 110.45) and alias it to a "total" column, how can I ensure that I end up with "121.25" and not "110.4510.80"?
Text strings are surrounded by quotes:
10.80 + 110.45 = 121.25
"10.80" + "110.45" = "10.80110.45"
10.80 + "110.45" = Error. You can't add a number to a string.
If you were using variables or field names instead of constants, it would depend on how they were defined; numeric or text.