SCCM Collection in DB - sccm

Is there information in the SCCM database about the date of adding a computer object to a given sccm collection?
I have write the SQL Query:
select v_R_System.Name0 as MemberName, v_Collection.Name as CollectionName, v_Collection.LastMemberChangeTime, v_Collection.LastChangeTime from v_FullCollectionMembership
Inner JOIN v_R_System on v_FullCollectionMembership.ResourceID = v_R_System.ResourceID
Inner JOIN v_Collection on v_FullCollectionMembership.CollectionID = v_Collection.CollectionID
Where v_Collection.Name like '%My SCCM Collection%'
Of course, the result concerns the modification of the collection itself, not the date of adding a computer object to this collection.
Thanks for any advice, where this information is or how I can get it.

Related

ORA-02019:connection description for remote database not found - left join in a view

I have 3 tables:
table1: id, person_code
table2: id, address, person_code_foreing(same with that one from table 1), admission_date_1
table3: id, id_table2, admission_date_2, something
(the tables are fictive)
I'm trying to make a view who takes infos from this 3 tables using left join, i'm doing like this because in the first table i have some record who don't have the person_code in the others tables but I want also this info to be returned by the view:
CREATE OR REPLACE VIEW schema.my_view
SELECT t1.name, t2.adress, t3.something
from schema.table1#ambient1 t1
left join schema.table2#ambient1 t2
on t1.person_code = t2.person_code_foreing
left join schema.table3#ambient1 t3
on t3.id_table2 = t2.id
and t1.admission_date_1=t2.admission_date_2;
This view needs to be created in another ambient (ambient2).
I tried using a subquery, there I need also a left join to use, and this thing is very confusing because I don't get it, the subquery and the left join are the big no-no?! Or just de left-join?!
Has this happened to anyone?
How did you risolved it?
Thanks a lot.
ORA-2019 indicates that your database link (#ambient1) does not exist, or is not visible to the current user. You can confirm by checking the ALL_DB_LINKS view, which should list all links to which the user has access:
select owner, db_link from all_db_links;
Also keep in mind that Oracle will perform the joins in the database making the call, not the remote database, so you will almost certainly have to pull the entire contents of all three tables over the network to be written into TEMP for the join and then thrown away, every time you run a query. You will also lose the benefit of any indexes on the data and most likely wind up with full table scans on the temp tables within your local database.
I don't know if this is an option for you, but from a performance perspective and given that it isn't joining with anything in the local database, it would make much more sense to create the view in the remote database and just query that through the database link. That way all of the joins are performed efficiently where the data lives, only the result set is pushed over the network, and your client database SQL becomes much simpler.
I managed to make it work, but apparently ambient2 doesn't like my "left-join", and i used only a subquery and the operator (+), this is how it worked:
CREATE OR REPLACE VIEW schema.my_view
SELECT t1.name, all.adress, all.something
from schema.table1#ambient1 t1,(select * from
schema.table3#ambient1 t3, schema.table2#ambient1 t2
where t3.id_table2 = t2.id(+)
and (t1.admission_date_1=t2.admission_date_2 or t1.admission_date is null))
all
where t1.person_code = t2.person_code_foreing(+);
I tried to test if a query in ambient2 using a right-join works (with 2 tables created there) and it does. I thought there is a problem with that ambient..
For me, there is no sense why in my case this kind of join retrieves that error.
The versions are different?! I don't know, and I don't find any official documentation about that.
Maybe some of you guys have any clue..
There is a mistery for me :))
Thanks.

I am studying Oracle, But We are Asked how to Select data from multiple tables without using JOIN clause

For Instance
Suppose You have multiple tables Like these!
**Students(StudId, Sname, SRegNo),
Lecturers(LectId, LectName, Lect Course),
Courses(CourseId, CourseName, Coursemarks)**
How can you Join them by Getting only, Sname, Lectname and CourseMarks

Replacing NOT IN with NOT EXISTS and an OUTER JOIN in Oracle Database 12c

I understand that the performance of our queries is improved when we use EXISTS and NOT EXISTS in the place of IN and NOT IN, however, is performance improved further when we replace NOT IN with an OUTER JOIN as opposed to NOT EXISTS?
For example, the following query selects all models from a PRODUCT table that are not in another table called PC. For the record, no model values in the PRODUCT or PC tables are null:
select model
from product
where not exists(
select *
from pc
where product.model = pc.model);
The following OUTER JOIN will display the same results:
select product.model
from product left join pc
on pc.model = product.model
where pc.model is null;
Seeing as these both return the same values, which option should we use to better improve the performance of our queries?
The query plan will tell you. It will depend on the data and tables. In the case of OUTER JOIN and NOT EXISTS they are the same.
However to your opening sentence, NOT IN and NOT EXISTS are not the same if NULL is accepted on model. In this case you say model cannot be null so you might find they all have the same plan anyway. However when making this assumption, the database must be told there cannot be nulls (using NOT NULL) as opposed to there simply not being any. If you don't it will make different plans for each query which may result in different performance depending on your actual data. This is generally true and particularly true for ORACLE which does not index NULLs.
Check out EXPLAIN PLAN

Query working in native Oracle sql but not through odbc. Alias from subquery is an invalid identifier

A collegue needs to work with this data in Excel. I wrote the query below. It runs fine when I run it from sql developer. But when I want to use it in Microsoft Query which apparently uses ODBC to connect to the Oracle database, I get an error that says that the identifier "due" is invalid.
But how can I name the sum from the subquery in the select part of the sql?
SELECT cl.clid, cl.cl_name, s.due, con.oid, con.contract_status
FROM clientinfo cl
LEFT OUTER JOIN
(SELECT clid, sum(dueamount) as due
from account GROUP BY clid) s
ON s.clid = cl.clid
LEFT OUTER JOIN contract con
ON con.clid = cl.clid
ORDER BY cl.clid
I translated the names into english so that the query makes a bit more sense to you. I want to show the client id and their names along with the due amount and an object number with the status of the contract.
Create a view in the Oracle DB and let your colleague query that view through ODBC.

Does this linq-to-sql query retrieve all records and then pick one, or retrieve just one?

I'm looking for the highest key in a table with a quite a lot of records, and I'm wondering if LINQ to SQL does this efficiently, or if I need to take another approach to make sure the code isn't pulling across all of the records from the database.
int tkey =
(from r in GMSCore.db.Receipts
orderby r.TransactionKey descending
select r.TransactionKey).FirstOrDefault();
Is this interpreted like:
select Top(1) TransactionKey
from Receipt
order by TransactionKey desc
Or does it pull all of the records and then filter in the C# code?
It retrieves just one record. Generated query will look like:
SELECT TOP(1) [t0].[TransactionKey]
FROM Receipt [t0]
ORDER BY [t0].[TransactionKey] DESC
Query is not executed until you call FirstOrDefault() or other operator which forces execution (see Classification of Standard Query Operators by Manner of Execution).
You even can save query definition into variable (feel the difference - not result of query execution, but query itself)
var query = from r in GMSCore.db.Receipts
orderby r.TransactionKey descending
select r.TransactionKey;
// Nothing is executed yet
int tkey = query.FirstOrDefault(); // SQL query is generated and executed
You can execute original query later
foreach(var key in query) // another SQL is generated and executed
// ...
But in this case generated SQL query will look like
SELECT [t0].[TransactionKey]
FROM Receipt [t0]
ORDER BY [t0].[TransactionKey] DESC
So, you can modify query definition until it is executed. E.g. you can add filtering, or change ordering. In fact operator which executes query also usually affects query generation - e.g. selecting first, single or max item.

Resources