Skip to content

Commit 1de6669

Browse files
committed
Update schema_statements.rb
1 parent 5b61f94 commit 1de6669

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,11 @@ def data_source_sql(name = nil, type: nil)
416416
database = scope[:database].present? ? "#{scope[:database]}." : ""
417417
table_catalog = scope[:database].present? ? quote(scope[:database]) : "DB_NAME()"
418418

419-
sql = "SELECT CONCAT(#{table_schema}, '.', #{table_name})"
419+
sql = "SELECT "
420+
sql += " CASE"
421+
sql += " WHEN #{table_schema} = 'dbo' THEN #{table_name}"
422+
sql += " ELSE CONCAT(#{table_schema}, '.', #{table_name})"
423+
sql += " END"
420424
sql += " FROM #{database}INFORMATION_SCHEMA.TABLES WITH (NOLOCK)"
421425
sql += " WHERE TABLE_CATALOG = #{table_catalog}"
422426
sql += " AND TABLE_SCHEMA = #{quote(scope[:schema])}" if scope[:schema]

0 commit comments

Comments
 (0)