something like belowDECLARE @ColumnList varchar(max),@SQL varchar(max)SELECT @ColumnList = COALESCE(@ColumnList+ ',','') + '@' + COLUMN_NAME + ' ' + DATA_TYPE + COALESCE('(' + CASEWHEN DATA_TYPE = 'XML' THEN NULLWHEN Cast(CHARACTER_MAXIMUM_LENGTH AS VARCHAR(5)) = -1 THEN 'max'ELSE Cast(CHARACTER_MAXIMUM_LENGTH AS VARCHAR(5))END + ')', '(' + Cast(NUMERIC_PRECISION AS NVARCHAR(5)) + ',' + Cast(NUMERIC_SCALE AS NVARCHAR(5)) + ')', '') + ' ' + CASE IS_NULLABLEWHEN 'YES' THEN 'NULL'ELSE 'NOT NULL'END + COALESCE(' DEFAULT ' + COLUMN_DEFAULT, '')FROM INFORMATION_SCHEMA.ColumnsWHERE table_name = 'Company'SELECT @SQL = 'declare ' + @ColumnListEXEC(@SQL)
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs