Percentage from Total SUM after GROUP BY SQL Server

You don’t need a cross join. Just use window functions: SELECT P.PersonID, SUM(PA.Total), SUM(PA.Total) * 100.0 / SUM(SUM(PA.Total)) OVER () AS Percentage FROM Person P JOIN Package PA ON P.PersonID = PA.PackageFK GROUP BY P.PersonID; Note that you do not need the JOIN for this query: SELECT PA.PersonID, SUM(PA.Total), SUM(PA.Total) * 100.0 / SUM(SUM(PA.Total)) OVER … Read more

conversion of a varchar data type to a datetime data type resulted in an out-of-range value

Ambiguous date formats are interpreted according to the language of the login. This works set dateformat mdy select CAST(’03/28/2011 18:03:40′ AS DATETIME) This doesn’t set dateformat dmy select CAST(’03/28/2011 18:03:40′ AS DATETIME) If you use parameterised queries with the correct datatype you avoid these issues. You can also use the unambiguous “unseparated” format yyyyMMdd hh:mm:ss

Can SQL Server SQL_Latin1_General_CP1_CI_AS be safely converted to Latin1_General_CI_AS?

Here is a more complete answer: https://www.olcot.co.uk/revised-difference-between-collation-sql_latin1_general_cp1_ci_as-and-latin1_general_ci_as/ The key difference between these collations is in how they apply character expansion rules. Certain Latin characters may be expanded into multiple characters. The SQL_xxxx collations may ignore these character expansions when working with non-unicode text, but apply them for unicode text. As a result: joins, sorts, and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)