• da-zero (4/12/2010)


    A small question:

    isn't the variable @InputStr stored somewhere? As the loop goes on forever, at some point in time that variable will become too large to reside in memory/physical location. So some sort of out of memory exception has to take place, right?

    SQL Server controls the amount of memory each request gets, and will spill to tempdb if the required memory exceeds the memory your request needs. So, no, you will not run out of memory. I did some testing, and it seems that when a variable exceeds 512KB it will start to use tempdb for storage. I have not found any information that can confirm my tests.

    Also, the trailing spaces are removed for nvarchar and varchar data types, so the length of the variable in this specific example will always be six bytes.