Hi,
I have to run a script that fetches some value (say Column1) from a particulat table (say Table 1) from all the databases in SQL Server.
Is there any way i can parameterize (USE 'DATABSENAME') Command.
Can I use something like
Declare @StudyName char(20)
Set @StudyName ='Master'
Use '@StudyName'
Please let me know any solution
1 3951
This is a code I found and modified that will give you all tables and all columns, I have used this as a building block to do many things;
a cursor sounds like what you will need if you want a result set from all of the databases at once. -
SET NOCOUNT ON
-
-
DECLARE @Return int
-
DECLARE @Retain int
-
DECLARE @Status int
-
DECLARE @PCIntra varchar(100)
-
DECLARE @PCUltra bit
-
-
set @PCIntra = '%'
-
set @PCUltra = 1
-
-
SET @Status = 0
-
-
DECLARE @TPre varchar(10)
-
-
DECLARE @TDo3 tinyint
-
DECLARE @TDo4 tinyint
-
-
SET @TPre = ''
-
-
SET @TDo3 = LEN(@TPre)
-
SET @TDo4 = LEN(@TPre) + 1
-
-
CREATE TABLE #DBAH (TName varchar(100),
-
CName varchar(100),
-
CList smallint,
-
CKind varchar(20),
-
CSize int,
-
CWide smallint,
-
CMore smallint)
-
-
INSERT #DBAH
-
SELECT O.name
-
, C.name
-
, C.colid
-
, T.name
-
, C.length
-
, C.prec
-
, C.scale
-
FROM sysobjects AS O
-
JOIN syscolumns AS C
-
ON O.id = C.id
-
JOIN systypes AS T
-
ON C.xusertype = T.xusertype
-
WHERE ISNULL(OBJECTPROPERTY(O.id,'IsMSShipped'),1) = 0
-
AND RTRIM(O.type) = 'U'
-
AND LEFT(O.name,@TDo3) = @TPre
-
AND O.name NOT LIKE 'adt%'
-
AND O.name NOT LIKE '%dtproper%'
-
AND O.name NOT LIKE 'dt[_]%'
-
-
AND (@PCIntra IS NULL OR C.name LIKE @PCIntra)
-
-
SET @Retain = @@ERROR IF @Status = 0 SET @Status = @Retain
-
-
SELECT CASE WHEN @PCUltra = 0 THEN SUBSTRING(TName,@TDo4,100) ELSE TName END AS TName, CName, CList, CKind, CSize, CWide, CMore FROM #DBAH ORDER BY TName, CList
-
-
DROP TABLE #DBAH
-
-
SET NOCOUNT OFF
-
-
SELECT (@Status)
-
-
GO
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Garry Clarke |
last post by:
Hi,
I've written a job to export user and database permissions for all
d/b's on a server. As you can see below, the T-SQL commands are the
same for each d/b. Can anyone assist with regard to...
|
by: Cara |
last post by:
LAST CALL FOR VOTES (of 2)
unmoderated group comp.databases.etl
Newsgroups line:
comp.databases.etl Extraction, transformation, loading issues.
Votes must be received by 23:59:59 UTC, 12 Dec...
|
by: Cara Altman |
last post by:
REQUEST FOR DISCUSSION (RFD)
unmoderated group comp.databases.etl
This is a formal Request For Discussion (RFD) for the creation of a
world-wide unmoderated Usenet newsgroup...
|
by: CLarkou |
last post by:
Is there any other way of looping in the fields of records in a
Datasheet form, except from the following one (moving to each record)
for checking the field values ?
For I = 1 To var_end_R...
|
by: dba_222 |
last post by:
Dear experts,
Again, sorry to bother you again with such a seemingly dumb question,
but I'm having some really mysterious results here.
ie.
Create procedure the_test
As
|
by: MP |
last post by:
Hi
trying to begin to learn database using vb6, ado/adox, mdb format, sql
(not using access...just mdb format via ado)
i need to group the values of multiple fields
- get their possible...
|
by: itfetish |
last post by:
Ok heres my problem, I have a database which has a table in it that
has all the staff members who are currently signed out of hte office.
That has their staff ID, and the time they are out till...
|
by: LostDeveloper via AccessMonster.com |
last post by:
Relationship goes Certification can have multiple variations (any single
variation satifies the certification), which require multiple course groups
which require any one of the products assigned...
|
by: aconti74 |
last post by:
Hello I am new to vba programming/coding. I am writing a program that
goes through a directory of text files and imports them into the
database. The problem is eventually the database gets to big...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |