Usually, it's a typical problem we will face while executing the Dynamic SQL the length of the string is really huge when compared to the max length of the string. To overcome this major issue. Here is a small alternative. We can have part of the execution string in one variable and remaining part in the other string.
A small example

find columns having index?

sp_help tblUserDetails

EXEC sp_msforeachtable @command1= "PRINT '?'
EXEC sp_helpindex @objname = '?'"



Join the conversation! Your thoughts help the community grow.