SQL Server String or binary data would be truncated

I am involved in a data migration project. I am getting the following error when I try to insert data from one table into another table (SQL Server 2005): Msg 8152, Level 16, State 13, Line 1 String or binary data would be truncated. The source data columns match the data type and are within … Read more

Best way to do nested case statement logic in SQL Server

I’m writing an SQL Query, where a few of the columns returned need to be calculated depending on quite a lot of conditions. I’m currently using nested case statements, but its getting messy. Is there a better (more organised and/or readable) way? (I am using Microsoft SQL Server, 2005) A simplified example: SELECT col1, col2, … Read more

SQL Server – transactions roll back on error?

We have client app that is running some SQL on a SQL Server 2005 such as the following: BEGIN TRAN; INSERT INTO myTable (myColumns …) VALUES (myValues …); INSERT INTO myTable (myColumns …) VALUES (myValues …); INSERT INTO myTable (myColumns …) VALUES (myValues …); COMMIT TRAN; It is sent by one long string command. If … Read more