How to truncate string using SQL server

If you only want to return a few characters of your long string, you can use: See SQL Fiddle with Demo. This will return the first 15 characters of the string and then concatenates the … to the end of it. If you want to to make sure than strings less than 15 do not … Read more

SUM OVER PARTITION BY

You could have used DISTINCT or just remove the PARTITION BY portions and use GROUP BY: Not sure why you are dividing the total by the count per BrandID, if that’s a mistake and you want percent of total then reverse those bits above to:

Arithmetic overflow error converting varchar to data type numeric. ’10’ <= 9.00

This generates an Arithmetic Overflow because it is trying to implicitly cast the Val column to a NUMERIC(3,2), which naturally will overflow on a 2-digit value like 10. It’s using NUMERIC(3,2) as the target type and size because that is the smallest numeric that 9.00 appears to fit into. The solution, of course, is to use explict CASTing instead … Read more