Sunday, February 19, 2012

I need help with my query

Hi Y'all,

I want to get all database-names from my server, i do that like this:

select name, dbid from sysdatabases => from my master database

Now i want to add a "where"-clause to select only those databases that have the table "TASKS".

Can someone help me out?

THanks

Hi,

If you are trying to get the list of tables, database name etc. in your ASP.Net application then have a look at it.http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbconnection.getoledbschematable.aspx

Thanks and best regards,

|||

this doesn't seem to work:

SET @.sSql = 'select * from ' + @.databasenaam + '.dbo.sysobjects where name like '''tablesearchnaam''' '


if exists(EXEC sp_sqlexec @.sSql)

|||Have you tried this already?

SELECT*FROM sysobjectsWHERE [name]LIKE'%tasks%'

This can also be done without using a stored procedure...

IFEXISTS(SELECT*FROM sysobjectsWHERE [name]LIKE'%tasks%')
DO STUFF

|||

If you just want tables you might want to restrict the type to 'U'.

SELECT*FROM sysobjectsWHERE [name]LIKE'%tasks%' AND Type = 'U'

No comments:

Post a Comment