Monday, March 26, 2012
Looping through list in a query
I am trying to write a query that will execute the same command to each
database in a list. More specifically I use the following command to get a
list of all the user-defined databases on the server:
SELECT catalog_name from information_schema.Schemata
WHERE NOT (CATALOG_NAME in
('tempdb','master','msdb','model','Northwind','pub s'))
and now I want to perfrom that same action (ie dettach or check for orphan
users etc) on each DB that I get from this query. Is there a way to do this
in SQL?
thanks
christos
Christos Kritikos wrote:
> Hello,
> I am trying to write a query that will execute the same command to
> each database in a list. More specifically I use the following
> command to get a list of all the user-defined databases on the server:
> SELECT catalog_name from information_schema.Schemata
> WHERE NOT (CATALOG_NAME in
> ('tempdb','master','msdb','model','Northwind','pub s'))
> and now I want to perfrom that same action (ie dettach or check for
> orphan users etc) on each DB that I get from this query. Is there a
> way to do this in SQL?
> thanks
> christos
Checking user information can be done in sysprocesses. No need to
enumerate the databases. If you really need a way to run the same
command against each database, you can use xp_MSForEachDB or just use a
temp table and interate through the results.
David Gugick
Imceda Software
www.imceda.com
Looping through Command Line Results...
I
know how to do that. What's the best practice for looping through the results
to find specific information from the results of the command line?
Say I want to search for a string "computername" in each returned row.
Thanks.
On Fri, 20 Jul 2007 10:32:05 -0700, Joe
<Joe@.discussions.microsoft.com> wrote:
>I want to run a command line utility and return the results. I'm pretty sure
>I
>know how to do that. What's the best practice for looping through the results
>to find specific information from the results of the command line?
>Say I want to search for a string "computername" in each returned row.
>Thanks.
There are diverse and contradictory way to interpret your question.
One would be that you want to run SQL Server commands from the command
prompt (sometimes called the DOS prompt). OSQL would let you run the
commands, and it is common to save the results to a .txt file. It is
possible to search a .txt file using the command line utility FIND.
Another interpretation of your question is that you intend to run
something from within SQL Server using xp_cmdshell and wish to search
the results. The approach in that case is to create a table with one
column (varchar(255) and then:
INSERT ThatTable (ThatColumn)
EXEC master..xp_cmdshell 'some command here'
After which you can search the table using SELECT and LIKE. If the
sequence of the rows is significant, include an IDENTITY column in the
table definition so that you can tell which order the rows came in.
A third interpreation could be that your question has nothing to do
with SQL Server and belongs somewhere else.
Perhaps you would like to clarify?
Roy Harvey
Beacon Falls, CT
|||Roy,
Thank you, and sorry for being unclear. The second answer is what I was
planning
and how I will do it. I just wasnt sure if I ran xp_cmdshell if I could
just loop
through the results without having to populate a table.
Thanks again.
"Roy Harvey" wrote:
> On Fri, 20 Jul 2007 10:32:05 -0700, Joe
> <Joe@.discussions.microsoft.com> wrote:
>
> There are diverse and contradictory way to interpret your question.
> One would be that you want to run SQL Server commands from the command
> prompt (sometimes called the DOS prompt). OSQL would let you run the
> commands, and it is common to save the results to a .txt file. It is
> possible to search a .txt file using the command line utility FIND.
> Another interpretation of your question is that you intend to run
> something from within SQL Server using xp_cmdshell and wish to search
> the results. The approach in that case is to create a table with one
> column (varchar(255) and then:
> INSERT ThatTable (ThatColumn)
> EXEC master..xp_cmdshell 'some command here'
> After which you can search the table using SELECT and LIKE. If the
> sequence of the rows is significant, include an IDENTITY column in the
> table definition so that you can tell which order the rows came in.
> A third interpreation could be that your question has nothing to do
> with SQL Server and belongs somewhere else.
> Perhaps you would like to clarify?
> Roy Harvey
> Beacon Falls, CT
>
Looping through Command Line Results...
e
I
know how to do that. What's the best practice for looping through the resul
ts
to find specific information from the results of the command line?
Say I want to search for a string "computername" in each returned row.
Thanks.On Fri, 20 Jul 2007 10:32:05 -0700, Joe
<Joe@.discussions.microsoft.com> wrote:
>I want to run a command line utility and return the results. I'm pretty su
re
>I
>know how to do that. What's the best practice for looping through the resu
lts
>to find specific information from the results of the command line?
>Say I want to search for a string "computername" in each returned row.
>Thanks.
There are diverse and contradictory way to interpret your question.
One would be that you want to run SQL Server commands from the command
prompt (sometimes called the DOS prompt). OSQL would let you run the
commands, and it is common to save the results to a .txt file. It is
possible to search a .txt file using the command line utility FIND.
Another interpretation of your question is that you intend to run
something from within SQL Server using xp_cmdshell and wish to search
the results. The approach in that case is to create a table with one
column (varchar(255) and then:
INSERT ThatTable (ThatColumn)
EXEC master..xp_cmdshell 'some command here'
After which you can search the table using SELECT and LIKE. If the
sequence of the rows is significant, include an IDENTITY column in the
table definition so that you can tell which order the rows came in.
A third interpreation could be that your question has nothing to do
with SQL Server and belongs somewhere else.
Perhaps you would like to clarify?
Roy Harvey
Beacon Falls, CT|||Roy,
Thank you, and sorry for being unclear. The second answer is what I was
planning
and how I will do it. I just wasnt sure if I ran xp_cmdshell if I could
just loop
through the results without having to populate a table.
Thanks again.
"Roy Harvey" wrote:
> On Fri, 20 Jul 2007 10:32:05 -0700, Joe
> <Joe@.discussions.microsoft.com> wrote:
>
> There are diverse and contradictory way to interpret your question.
> One would be that you want to run SQL Server commands from the command
> prompt (sometimes called the DOS prompt). OSQL would let you run the
> commands, and it is common to save the results to a .txt file. It is
> possible to search a .txt file using the command line utility FIND.
> Another interpretation of your question is that you intend to run
> something from within SQL Server using xp_cmdshell and wish to search
> the results. The approach in that case is to create a table with one
> column (varchar(255) and then:
> INSERT ThatTable (ThatColumn)
> EXEC master..xp_cmdshell 'some command here'
> After which you can search the table using SELECT and LIKE. If the
> sequence of the rows is significant, include an IDENTITY column in the
> table definition so that you can tell which order the rows came in.
> A third interpreation could be that your question has nothing to do
> with SQL Server and belongs somewhere else.
> Perhaps you would like to clarify?
> Roy Harvey
> Beacon Falls, CT
>
Looping through Command Line Results...
I
know how to do that. What's the best practice for looping through the results
to find specific information from the results of the command line?
Say I want to search for a string "computername" in each returned row.
Thanks.On Fri, 20 Jul 2007 10:32:05 -0700, Joe
<Joe@.discussions.microsoft.com> wrote:
>I want to run a command line utility and return the results. I'm pretty sure
>I
>know how to do that. What's the best practice for looping through the results
>to find specific information from the results of the command line?
>Say I want to search for a string "computername" in each returned row.
>Thanks.
There are diverse and contradictory way to interpret your question.
One would be that you want to run SQL Server commands from the command
prompt (sometimes called the DOS prompt). OSQL would let you run the
commands, and it is common to save the results to a .txt file. It is
possible to search a .txt file using the command line utility FIND.
Another interpretation of your question is that you intend to run
something from within SQL Server using xp_cmdshell and wish to search
the results. The approach in that case is to create a table with one
column (varchar(255) and then:
INSERT ThatTable (ThatColumn)
EXEC master..xp_cmdshell 'some command here'
After which you can search the table using SELECT and LIKE. If the
sequence of the rows is significant, include an IDENTITY column in the
table definition so that you can tell which order the rows came in.
A third interpreation could be that your question has nothing to do
with SQL Server and belongs somewhere else.
Perhaps you would like to clarify?
Roy Harvey
Beacon Falls, CT|||Roy,
Thank you, and sorry for being unclear. The second answer is what I was
planning
and how I will do it. I just wasnt sure if I ran xp_cmdshell if I could
just loop
through the results without having to populate a table.
Thanks again.
"Roy Harvey" wrote:
> On Fri, 20 Jul 2007 10:32:05 -0700, Joe
> <Joe@.discussions.microsoft.com> wrote:
> >I want to run a command line utility and return the results. I'm pretty sure
> >I
> >know how to do that. What's the best practice for looping through the results
> >to find specific information from the results of the command line?
> >
> >Say I want to search for a string "computername" in each returned row.
> >
> >Thanks.
> There are diverse and contradictory way to interpret your question.
> One would be that you want to run SQL Server commands from the command
> prompt (sometimes called the DOS prompt). OSQL would let you run the
> commands, and it is common to save the results to a .txt file. It is
> possible to search a .txt file using the command line utility FIND.
> Another interpretation of your question is that you intend to run
> something from within SQL Server using xp_cmdshell and wish to search
> the results. The approach in that case is to create a table with one
> column (varchar(255) and then:
> INSERT ThatTable (ThatColumn)
> EXEC master..xp_cmdshell 'some command here'
> After which you can search the table using SELECT and LIKE. If the
> sequence of the rows is significant, include an IDENTITY column in the
> table definition so that you can tell which order the rows came in.
> A third interpreation could be that your question has nothing to do
> with SQL Server and belongs somewhere else.
> Perhaps you would like to clarify?
> Roy Harvey
> Beacon Falls, CT
>sql
Monday, March 12, 2012
Lookup and OLEDB Command components programming
The SCD Wizard produces a data-flow with an OLE DB Command in it so you could look at that!
-Jamie|||And how can I get a code from SCD Wizard?|||
Erch wrote:
And how can I get a code from SCD Wizard?
You can't. The SCD Wizard produces components, not code.
So am I correct in saying that you want to build a package programatically that contains a data-flow containing a LOOKUP and an OLE DB COMMAND? There isn't much resources around yet that shows how to do this - BOL is definately the best place to go.
-Jamie
Saturday, February 25, 2012
Looking for information
I'm looking for books or information on command line configuration of settings for things like activating Remote Connections under the Service Area Configuration and setting a port for that connection.
What books would be good to get or where can I download papers on this?
Any help would be appreciated.
I'd say the best place to start would be SQL Books Online, http://msdn2.microsoft.com, or you can download them from the Microsoft Download Center, http://www.microsoft.com/downloads.
You can run command line configuration through the SACUtility, check out the BOL topic at http://msdn2.microsoft.com/en-us/library/ms162800.aspx.
I don't have any personal recomendations for books you can read, but a quick search gave me Microsoft SQL Server 2005 Administrator's Pocket Consultant from MS Press (http://www.microsoft.com/MSPress/books/6794.asp). Probably a bunch of interesting things in there. It mentions having a section on Install, configure and tune SQL Server.
Hope this helps.
Mike Wachal
SQL Express team