Hello,
Does anyone know how to return the name of all the databases except the system databases on a server for SQL Server 2005?
Thank you
select * from sys.databases where database_id not in (1, 2, 3, 4)
|||Thank you!Hello,
Does anyone know how to return the name of all the databases except the system databases on a server for SQL Server 2005?
Thank you
select * from sys.databases where database_id not in (1, 2, 3, 4)
|||Thank you!Hello,
Is it possible to return all the field names of a database. I do not want the data rows. Just a list of fields in the databse.
Thanks
Something like this will do it
Use YourDBName
select table_name, column_name, ordinal_position, data_type
from information_schema.columns
order by 1,3
|||Thanks for that.
I am trying this
Use CallsAndIncidents
select PROBSUMMARYM1
from information_schema.columns
I have my database as HOUAPPS237.CallsAndIncidents.dbo.PROBSUMMARYM1
where PROBSUMMARYM1 is the table name whose fields I want returned . i.e Name,Type ,Level,etc.
I did not understand these 2 lines
select table_name, column_name, ordinal_position, data_type
from information_schema.columns
what should be column_name(many columns), ordinal_position(?), data_type(different data types),information_schema.columns(?)
Thanks for the help Will.
Kiran
|||... just run this - don't change the SQL
USE HOUAPPS237.CallsAndIncidents.dbo.PROBSUMMARYM1
select table_name, column_name, ordinal_position, data_type
from information_schema.columns
and see what you get
or even
USE PROBSUMMARYM1
select table_name, column_name, ordinal_position, data_type
from information_schema.columns
|||
THANKS WILL,
WORKED GREAT
Only change I had to do was from
USE HOUAPPS237.CallsAndIncidents.dbo.PROBSUMMARYM1
select table_name, column_name, ordinal_position, data_type
from information_schema.columns
to
USE CallsAndIncidents
select table_name, column_name, ordinal_position, data_type
from information_schema.columns
Thanks a bunch
Hi,
SQL Server has built-in proceduresp_databases to do that. You just need to have permissions to execute it.
Does anyone know how to return a list of element names from an xml document?
eg.
Code Snippet
<values>
<name>Brian</name>
<lastName>Smith</lastName>
<tel>999-123456</tel>
</values>
the result set I'm after is a table with two columns (lets say col_name and col_value)
col_name col_value
name Brian
lastName Smith
tel 999-123456
my biggest problem is extracting the element name - any ideas
Many Thanks,
Jan.
Here is an example doing that using the XQuery nodes method to shred the XML into nodes and then the local-name XQuery function:
Code Snippet
DECLARE @.x xml;
SET @.x ='<values>
<name>Brian</name>
<lastName>Smith</lastName>
<tel>999-123456</tel>
</values>';
SELECT
T.xcol.value('local-name(.)','nvarchar(20)')AScol_name
,T.xcol.value('.','nvarchar(20)')AS col_value
FROM @.x.nodes('*/*')AS T(xcol);
|||Cheers Martin,Exactly what I was after !
The code is something like that.
DSO.Server srv = new DSO.Server();
srv.Connect("localhost");
after that i do not what to do in order to get the cube names from AM2000.
when i do the following
srv.MDStore.Count
i can get the number of the cubes but i cant get the names.
I tried to use the following method but did not work out.
srv.MDStore.Item(object vntIndexKey)
May be i do not know how to use the above method to get the cube names.
for(int i = 0; i < srv.MDStore.Count; i++)
combobox1.Item.Add(srv.MDStore.Item(i).ToString());
the above code does not add the cube names into combobox, either.
(
Please somebody help me with this problem.
I need to get the cube names from the AM2000 to let the user choose what cube he/she wants to work with!?
thanks in advance
best regards
Tunc OVACIK
DSO is the wrong API to use for something ordinary users need to run. DSO is the admin API and will only work for OLAP Administrators.
You should use the ADOMD or ADOMD.NET api, the MDX Sample app has code that does this using the older ADOMD API.
There is a sample in BOL for using ADOMD.NET to get a list of cubes which I have copied out below, the original page is available here
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/adodw9/html/0183dcdc-f2ea-4246-ad00-6e8ccc9d8217.htm
Code Snippet
private string RetrieveCubesAndDimensions()
{
System.Text.StringBuilder result = new System.Text.StringBuilder();
//Connect to the local server
using (AdomdConnection conn = new AdomdConnection("Data Source=localhost;"))
{
conn.Open();
//Loop through every cube
foreach (CubeDef cube in conn.Cubes)
{
//Skip hidden cubes.
if (cube.Name.StartsWith("$"))
continue;
//Write the cube name
result.AppendLine(cube.Name);
//Write out all dimensions, indented by a tab.
foreach (Dimension dim in cube.Dimensions)
{
result.Append("\t");
result.AppendLine(dim.Name);
}
}
//Close the connection
conn.Close();
}
//Return the results
return result.ToString();
}
Hello again,
I have succedded to get the cube names from AM2000 by using DSO API. To do this job with DSO API is very easy.
For further information for the others who may need it I will give the sample code.
string[] cubeNames;
DSO.Server dsoServer = new DSO.Server();
dsoServer.Connect("localhost");
// Count will return the number of cubes on AM2000
cubeNames = new string[dsoServer.MDStore.Count];
int i = 0;
foreach( DSO.MDStore cube in dsoServer.MDStore)
{
cubeNames
= cube.Name;
i++;
}
Before going through the code you should add the relevant .dll file into your project from the "Add Reference" menu.
Actually it is possible to get the cube names by using ADOMD classes as well as Darren said. I thank you for your help which was really usefull. So, the next step for me is to go through the cube and get the neccesarry data I need to make report for the user.
thanks for everything
Tunc OVACIK
|||The DSO code will only work for administrators, you can run it because you are an admin, normal users will not be able to run it. Hence the reason I suggested using Adomd.The code is something like that.
DSO.Server srv = new DSO.Server();
srv.Connect("localhost");
after that i do not what to do in order to get the cube names from AM2000.
when i do the following
srv.MDStore.Count
i can get the number of the cubes but i cant get the names.
I tried to use the following method but did not work out.
srv.MDStore.Item(object vntIndexKey)
May be i do not know how to use the above method to get the cube names.
for(int i = 0; i < srv.MDStore.Count; i++)
combobox1.Item.Add(srv.MDStore.Item(i).ToString());
the above code does not add the cube names into combobox, either.
(
Please somebody help me with this problem.
I need to get the cube names from the AM2000 to let the user choose what cube he/she wants to work with!?
thanks in advance
best regards
Tunc OVACIK
DSO is the wrong API to use for something ordinary users need to run. DSO is the admin API and will only work for OLAP Administrators.
You should use the ADOMD or ADOMD.NET api, the MDX Sample app has code that does this using the older ADOMD API.
There is a sample in BOL for using ADOMD.NET to get a list of cubes which I have copied out below, the original page is available here
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/adodw9/html/0183dcdc-f2ea-4246-ad00-6e8ccc9d8217.htm
Code Snippet
private string RetrieveCubesAndDimensions()
{
System.Text.StringBuilder result = new System.Text.StringBuilder();
//Connect to the local server
using (AdomdConnection conn = new AdomdConnection("Data Source=localhost;"))
{
conn.Open();
//Loop through every cube
foreach (CubeDef cube in conn.Cubes)
{
//Skip hidden cubes.
if (cube.Name.StartsWith("$"))
continue;
//Write the cube name
result.AppendLine(cube.Name);
//Write out all dimensions, indented by a tab.
foreach (Dimension dim in cube.Dimensions)
{
result.Append("\t");
result.AppendLine(dim.Name);
}
}
//Close the connection
conn.Close();
}
//Return the results
return result.ToString();
}
Hello again,
I have succedded to get the cube names from AM2000 by using DSO API. To do this job with DSO API is very easy.
For further information for the others who may need it I will give the sample code.
string[] cubeNames;
DSO.Server dsoServer = new DSO.Server();
dsoServer.Connect("localhost");
// Count will return the number of cubes on AM2000
cubeNames = new string[dsoServer.MDStore.Count];
int i = 0;
foreach( DSO.MDStore cube in dsoServer.MDStore)
{
cubeNames
= cube.Name;
i++;
}
Before going through the code you should add the relevant .dll file into your project from the "Add Reference" menu.
Actually it is possible to get the cube names by using ADOMD classes as well as Darren said. I thank you for your help which was really usefull. So, the next step for me is to go through the cube and get the neccesarry data I need to make report for the user.
thanks for everything
Tunc OVACIK
|||The DSO code will only work for administrators, you can run it because you are an admin, normal users will not be able to run it. Hence the reason I suggested using Adomd.This what I have tried that does not work:
SELECT first_name, last_name FROM contacts WHERE created_by_user_id = '" + uid + "' AND contact_id NOT EXISTS (SELECT * FROM deleted_contacts);
Any help woudl be greatly appreciated!
Thanks!
-DAGTA
SELECT first_name, last_name FROM contacts WHERE created_by_user_id = '" + uid + "' AND contact_id NOT EXISTS (SELECT * FROM deleted_contacts WHERE contact_id = your_contact_id_here);
NOT EXISTS checks to see whether the subquery that you provide returns at least 1 row. Since you were selecting everything from deleted_contacts, NOT EXISTS (SELECT * FROM deleted_contacts) always returned false. Instead, see if a row exists in deleted_contact that contains the specific contact_id that you're looking for.|||Have you tried:
AND contact_id NOT In(Select contact_id from...)|||Left join them
select Table1.ColumnName, ...
from Table1
left join Table2
on Table1.ID = Table2.ID
where Table2.ID is null
I don't like the Not In subquery thing.|||Thanks for the replies. I haven't tried the left join, yet.
The NOT IN method returns this error:
"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."
To be clearer on the problem:
We have a contacts table. When a user deletes a contact, the contact is not really deleted. Instead, it's contact_id is placed in a deleted_contacts table.
I'm trying to pull a list of contacts for a user. I don't want to pull any contacts that have been 'deleted'. As such, I do not have a specific contact id. I have a created_by_user_id which is only in the contacts table, not the deleted_contacts table.
Thanks for the help!
-DAGTA|||The LEFT JOIN seems to be working. Thank you Pierre!
-DAGTA|||No problem.
I think the Not In solution is slightly faster for small resultsets, but since the Left Join method is more scalable, I tend to not worry about it too much - and I just use the Left Join method all the time.|||I see that you ended up using a LEFT JOIN, which is fine. But to elaborate a little bit on using the NOT EXISTS functionality, I have this question for you: what is the unique identifier for a given customer? Both the "contacts" and "deleted_contacts" tables have to have a relationship, or else you can't check whether a given contact is also in the "deleted_contacts" table. In other words, in the "contacts" table, you need to have a field that unique differentiates each contact from another (identity column). Suppose that's a "ContactID"field. This field has to also exist in the "deleted_contacts" table. That's how you can check, for any given record in "contacts", does it exist in the "deleted_contacts" table as well! Otherwise, you can't tie the two tables together (that's the "relational" part in Relational Databases).
By the way, use NOT EXISTS rather than NOT IN. NOT EXISTS returns true if no rows are returned by the query defined inside the NOT EXISTS () parentheses. If it returns one or more rows, it evaluates to false.
Hope this helps.
P.S. By all means, use a left join. It really doesn't matter.|||Ah yup, Not Exists is much better than Not In. I really don't like the Not In thing, even for small subqueries.
Not Exists will probably work well even on large resultsets.
thanks in advance.
best regards
Tunc OVACIK
Check out Analysis Management Objects (AMO).
http://msdn2.microsoft.com/en-us/library/ms124924.aspx
|||Thanks for the link which is very usefull and has good informations about the whole programming stuff of OLAP technology but I guess those classes are for Analysis Manager 2005.thanks for your time
best regards
Tunc OVACIK|||
In that case, check out Decision Support Objects (DSO)
http://msdn2.microsoft.com/en-us/library/aa902639(sql.80).aspx
http://msdn2.microsoft.com/en-us/library/ms133828.aspx
How can I get a list of the names of the tables inside a database?
The following command will do that trick:
Code Snippet
SELECT * FROM INFORMATION_SCHEMA.TABLES
I this actually possible? All my research to date suggests that it is not. I know it can be done using XMLA or AMO but these are not available from Reporting Services right?
My goal is to retrieve a list of KPI Names to Reporting Services. These names will then be used as the allowed values list of a paremeter for a KPI report. I previously managed to do it for calculated measures using EXCEPT([Measures].AllMembers, [Measures].Members).
I can currently think of three options, none of which I like!
1) Create SQL CLR Proc and use AMO to retrieve KPI Names and return result set
2) Create SQL CLR Proc and use XMLA to retrieve KPI Names and return result set
3) Periodically run some app which uses one of the above methods to populate a "Current Set of KPIs" table
Please, somebody tell me there is another way :)
Eventually I worked out a way to do it. I found that there is a "OLEDb Schema GUID" for KPIs in SSAS. I wrote a SQL CLR Procedure to connect to SSAS via OLEDB but I afterwards realised SQL Server 2005's OPENROWSET would probably have done the trick too. Anyway, the code I used in SQL CLR is:
Code Snippet
// Open the Analysis Server connection
DataTable dt = new DataTable();
SqlMetaData[] metaData;
using (OleDbConnection cnn = new OleDbConnection(cnn_str))
{
cnn.Open();
// Execute the XMLA Schema request, convert rows to SqlDataRecord for sending to the Pipe.
Guid guid = new Guid("{2AE44109-ED3D-4842-B16F-B694D1CB0E3F}"); // The GUID for MDSCHEMA_KPIS
dt = cnn.GetOleDbSchemaTable(guid, null);
}Yay, I now have a way to list KPIs in Reporting Services.|||The ASSP project (a .NET stored proc project for SSAS) has a way to do just what you're looking for:
CALL ASSP.Discover("MDSCHEMA_KPIS")
http://www.codeplex.com/ASStoredProcedures/Wiki/View.aspx?title=XmlaDiscover&referringTitle=Home
|||Thankyou kindly furmangg, this is excellent. And to think, I ended up writing a CLR SP using OleDb to query SSAS...I can't believe I overlooked the ASSP project, it is full of so much useful stuff.
I this actually possible? All my research to date suggests that it is not. I know it can be done using XMLA or AMO but these are not available from Reporting Services right?
My goal is to retrieve a list of KPI Names to Reporting Services. These names will then be used as the allowed values list of a paremeter for a KPI report. I previously managed to do it for calculated measures using EXCEPT([Measures].AllMembers, [Measures].Members).
I can currently think of three options, none of which I like!
1) Create SQL CLR Proc and use AMO to retrieve KPI Names and return result set
2) Create SQL CLR Proc and use XMLA to retrieve KPI Names and return result set
3) Periodically run some app which uses one of the above methods to populate a "Current Set of KPIs" table
Please, somebody tell me there is another way :)
Eventually I worked out a way to do it. I found that there is a "OLEDb Schema GUID" for KPIs in SSAS. I wrote a SQL CLR Procedure to connect to SSAS via OLEDB but I afterwards realised SQL Server 2005's OPENROWSET would probably have done the trick too. Anyway, the code I used in SQL CLR is:
Code Snippet
// Open the Analysis Server connection
DataTable dt = new DataTable();
SqlMetaData[] metaData;
using (OleDbConnection cnn = new OleDbConnection(cnn_str))
{
cnn.Open();
// Execute the XMLA Schema request, convert rows to SqlDataRecord for sending to the Pipe.
Guid guid = new Guid("{2AE44109-ED3D-4842-B16F-B694D1CB0E3F}"); // The GUID for MDSCHEMA_KPIS
dt = cnn.GetOleDbSchemaTable(guid, null);
} Yay, I now have a way to list KPIs in Reporting Services.|||The ASSP project (a .NET stored proc project for SSAS) has a way to do just what you're looking for:
CALL ASSP.Discover("MDSCHEMA_KPIS")
http://www.codeplex.com/ASStoredProcedures/Wiki/View.aspx?title=XmlaDiscover&referringTitle=Home
|||Thankyou kindly furmangg, this is excellent. And to think, I ended up writing a CLR SP using OleDb to query SSAS...I can't believe I overlooked the ASSP project, it is full of so much useful stuff.