DECLARE @B INT, @Definition NVARCHAR(MAX)
SELECT @Definition = N'SELECT @B = ' + OBJECT_DEFINITION (default_object_id)
from sys.columns where name='COLUMN' AND OBJECT_ID= OBJECT_ID('TABLENAME')
EXEC SYS.SP_EXECUTESQL
@Definition, N'@B INT OUTPUT', @B = @B OUTPUT
select @B DF;
Running this in sql server 2008 r2 is giving me the correct answer. But any other attempts to incorporate it in stored procedure or as sql text in my queries on my pages fails miserably. The most often answer I am getting is "Item cannot be found in the collection corresponding to the requested name or ordinal". Any tips will be very much appreciated Thank you