Sub ConnectSqlServer() Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim sConnString As String Dim squery As String ' Create the connection string. sConnString = "Provider=SQLOLEDB;Data Source=RCHNLPT136\SQLEXPRESS2014;" & _ "Initial Catalog=ExpenseMgmt;" & _ "user id=sa;password=Welcome@123;" & _ "Integrated Security=SSPI;" ' Create the Connection and Recordset objects. Set conn = New ADODB.Connection Set rs = New ADODB.Recordset ' Open the connection and execute. conn.Open sConnString squery = "select " & _ " tb.TABLE_SCHEMA as TableSchema, tb.TABLE_NAME as TableName," & _ " sum(Case When DATA_TYPE = 'int' then 4 else 0 end + Case When DATA_TYPE = 'nvarchar' and CHARACTER_MAXIMUM_LENGTH > 0 then CHARACTER_MAXIMUM_LENGTH * 2 When DATA_TYPE =
select tb.TABLE_SCHEMA as TableSchema, tb.TABLE_NAME as TableName, sum( Case When DATA_TYPE = 'int' then 4 else 0 end + Case When DATA_TYPE = 'nvarchar' and CHARACTER_MAXIMUM_LENGTH > 0 then CHARACTER_MAXIMUM_LENGTH * 2 When DATA_TYPE = 'nvarchar' and CHARACTER_MAXIMUM_LENGTH < 0 then 8000 else 0 end + Case When DATA_TYPE = 'varchar' then CHARACTER_MAXIMUM_LENGTH else 0 end + Case When DATA_TYPE = 'Char' then CHARACTER_MAXIMUM_LENGTH else 0 end + Case When DATA_TYPE = 'nchar' then CHARACTER_MAXIMUM_LENGTH * 2 else 0 end + Case When DATA_TYPE = 'decimal' then 8 else 0 end + Case When DATA_TYPE = 'bit' then 1 else 0 end + Case When DATA_TYPE = 'Tinyint' then 1 else 0 end + Case When DATA_TYPE = 'Smallint' then 2 else 0 end + Case When DATA_TYPE = 'Smallint' t