Question

I'm inserting the result set returned from a CLR stored procedure into a table variable. I get the error: "System.Data.SqlClient.SqlException: String or binary data would be truncated", because some strings' lengths in the result set exceed the varchar limit defined in the temporary table. The annoying thing is, truncation is exactly what I want!
So, how do I truncate (the strings in) the result set from the stored procedure, upon inserting it?
I'd rather not change the code of the CLR SP. The strings in the data that's being inserted are of arbitrary length.

Was it helpful?

Solution

I think I'd make the columns of the temp table large enough to accept the data, then truncate after the insert, e.g.,

UPDATE #YourTempTable
    SET ColumnA = LEFT(ColumnA, 20),
        ColumnB = LEFT(ColumnB, 50)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top