Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Comparing Databases

Author  Topic 

kenaman
Starting Member

1 Post

Posted - 2003-03-20 : 03:53:26
I am running a stored procedure that compares the structure of 2 databases and am encountering an error at the following line. I need some help concatenating this string :


set @Sqlstring = ' select distinct table_name from Kenneth.INFORMATION_SCHEMA.tables ' +
'where table_schema = "dbo" ' +
'and table_type = "BASE TABLE" ' +
'and table_name = "' + @TableName1 + '"'


I have been trying to get the double quotes out of the equation but to no avail.
Any help would be appreciated.

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-03-20 : 04:05:43
Try using two single quotes

set @Sqlstring = 'select * from INFORMATION_SCHEMA.tables ' +
'where table_schema = ''dbo'' ' +
'and table_type = ''BASE TABLE'' ' +
'and table_name = ''' + @TableName1 + ''''


OS

Go to Top of Page

JellyRoll
Starting Member

8 Posts

Posted - 2003-03-24 : 10:53:20
I don't think I'd be too far off-topic if I mentioned that there are commercial products that will compare database schema. You could save lots of time and we all know time=money

Follow the link for a list:

http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=Compare+SQL&btnG=Google+Search

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-24 : 12:29:18
I recommend this tool:
[url]http://www.red-gate.com/sql_tools.htm[/url]

But if you can get your stored procedure to work, then go with that because it's free!

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-03-24 : 14:16:31
How about:

Declare @dbname1 sysname, @dbname2 sysname, @SQL varchar(4000)

Select @dbname1 = 'PUBS', @dbname2 = 'Northwind'

Set @SQL = 'SELECT * FROM '+@dbname1+'.information_schema.tables a '
+ 'full join '+@dbname2+'.information_schema.tables b '
+ 'On a.table_name = b.table_name and a.table_type = b.table_type'

Exec(@SQL)



Brett

8-)
Go to Top of Page
   

- Advertisement -