Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to write a SQLsubquery
where i search a database and then search a particular table from that database.

USE test SELECT * FROM sys.Tables order by name

this above query select all the tables from test database.

Now i want to search a particular table named "testing" in "test" database

how do i write this sqlsubquery?
please help me.
Thanks in advance
Posted

try this
SQL
Select * from <dbname>.dbo.sysobjects where name = '<tablename>'
 
Share this answer
 
v2
this will give you table and view of name "testing" :
SQL
.test.dbo.sp_tables 'testing'

hope this will help you.
And don't forget to mark as answer if it helps. :)
 
Share this answer
 
Hi Biswarup


SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE NAME'


use this query
 
Share this answer
 
SQL
declare @sqlQuery varchar(500);

select @sqlQuery=(case when 1=1 then 'select *from Test1.dbo.Testing'
 else 'select *from Test2.dbo.Testing' end)
 exec (@sqlQuery)
 
Share this answer
 
SQL
SELECT * from sysobjects where [type] in ('U') and name like '%tablename%'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900