I am trying to have a sccm 2007 collection query which can populate "not approved" and assigned to site code "AA1" - machines. Any suggestions ?
You can find things like this by googling 'SCCM Collection Query' and then describe what you're looking for.
Here's how to do your particular task:
select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,
SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,
SMS_R_SYSTEM.ResourceDomainORWorkgroup,
SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_CM_RES_COLL_SMS00001 on
SMS_CM_RES_COLL_SMS00001.ResourceId = SMS_R_System.ResourceId
where SMS_CM_RES_COLL_SMS00001.IsApproved= ‘0‘ and SMS_R_System.SMSInstalledSites = "XYZ"
The juciest bits are in the last two lines, while the remainder in the beginning is kind of just SCCM WQL Cruft:
where SMS_CM_RES_COLL_SMS00001.IsApproved= ‘0‘ and SMS_R_System.SMSInstalledSites = "XYZ"
Related
Warning, I am a complete noob with SQLite and Node-Red.
I am working on a project to scan and read car license plates. I now have the hardware up and running, it is passing plate information to a very basic SQLite 3 table of two records through Node-Red on a Raspberry Pi 3.
I can run instant queries, where a module sends over an exact query to run, ie
SELECT "License_Plate" FROM QuickDirtyDB WHERE "License_Plate" LIKE "%RAF66%"
This will come back with my plate RAF660, as below
topic: "SELECT "License_Plate" FROM QuickDirtyDB WHERE "License_Plate" LIKE "%RAF66%""
payload: array[1]
0: object
License_Plate: "RAF660"
When I automate and run this query it will not work, have been playing with this for three days now.
I am even unable to get a very basic automated query to work like
'var readlpr = msg.payload;
msg.topic = 'SELECT "License_Plate" FROM QuickDirtyDB WHERE "License_Plate" = ' + readlpr + ''
return msg;'
that's two single quotes at the end of the query line.
This is sent through to the query as below, it is the output from the debug node, exactly what is going into the query.
"SELECT "License_Plate" FROM QuickDirtyDB WHERE "License_Plate" = RAF660 "
and the error that comes out is,
"Error: SQLITE_ERROR: no such column: RAF660"
After this is working, I need to work out how I can allow a mismatch of two characters in case the OCR software either misread two characters or even drops two characters entirely. Is this something that a query can handle, or will I have to pass many plate details to a program to work out if I have a match?
I thought I would have had to run a query to create some kind of a view and then requery my read plate vs that view to see which plate in the database is the closest match, not sure if I have the terminology correct, view, join, union etc.
Thank you for looking and any suggestions you may have.
I will probably be going home in about an hour, so may not be able to check back in till Monday
RAF660 is a string and needs to be quoted "RAF660"
License_Plate is a column and should not be quoted.
The way you have it reads as fetch the rows where the RAF660 column is set to the value "License_Plate".
I'm trying to resolve below issue:
I need to prepare table that consists 3 columns:
user_id,
month
value.
Each from over 200 users has got different values of parameters that determine expected value which are: LOB, CHANNEL, SUBSIDIARY. So I decided to store it in table ASYSTENT_GOALS_SET. But I wanted to avoid multiplying rows and thought it would be nice to put all conditions as a part of the code that I would use in "where" clause further in procedure.
So, as an example - instead of multiple rows:
I created such entry:
So far I created testing table ASYSTENT_TEST (where I collect month and value for certain user). I wrote a piece of procedure where I used BULK COLLECT.
declare
type test_row is record
(
month NUMBER,
value NUMBER
);
type test_tab is table of test_row;
BULK_COLLECTOR test_tab;
p_lob varchar2(10) :='GOSP';
p_sub varchar2(14);
p_ch varchar2(10) :='BR';
begin
select subsidiary into p_sub from ASYSTENT_GOALS_SET where user_id='40001001';
execute immediate 'select mc, sum(ppln_wartosc) plan from prod_nonlife.mis_report_plans
where report_id = (select to_number(value) from prod_nonlife.view_parameters where view_name=''MIS'' and parameter_name=''MAX_REPORT_ID'')
and year=2017
and month between 7 and 9
and ppln_jsta_symbol in (:subsidiary)
and dcs_group in (:lob)
and kanal in (:channel)
group by month order by month' bulk collect into BULK_COLLECTOR
using p_sub,p_lob,p_ch;
forall x in BULK_COLLECTOR.first..BULK_COLLECTOR.last insert into ASYSTENT_TEST values BULK_COLLECTOR(x);
end;
So now when in table ASYSTENT_GOALS_SET column SUBSIDIARY (varchar) consists string 12_00_00 (which is code of one of subsidiary) everything works fine. But the problem is when user works in two subsidiaries, let say 12_00_00 and 13_00_00. I have no clue how to write it down. Should SUBSIDIARY column consist:
'12_00_00','13_00_00'
or
"12_00_00","13_00_00"
or maybe
12_00_00','13_00_00
I have tried a lot of options after digging on topics like "Deling with single/escaping/double qoutes".
Maybe I should change something in execute immediate as well?
Or maybe my approach to that issue is completely wrong from the very beginning (hopefully not :) ).
I would be grateful for support.
I didn't create the table function described here but that article inspired me to go back to try regexp_substr function again.
I changed: ppln_jsta_symbol in (:subsidiary) to
ppln_jsta_symbol in (select regexp_substr((select subsidiary from ASYSTENT_GOALS_SET where user_id=''fake_num''),''[^,]+'', 1, level) from dual
connect by regexp_substr((select subsidiary from ASYSTENT_GOALS_SET where user_id=''fake_num''), ''[^,]+'', 1, level) is not null) Now it works like a charm! Thank you #Dessma very much for your time and suggestion!
"I wanted to avoid multiplying rows and thought it would be nice to put all conditions as a part of the code that I would use in 'where' clause further in procedure"
This seems a misguided requirement. You shouldn't worry about number of rows: databases are optimized for storing and retrieving rows.
What they are not good at is dealing with "multi-value" columns. As your own solution proves, it is not nice, it is very far from nice, in fact it is a total pain in the neck. From now on, every time anybody needs to work with subsidiary they will have to invoke a function. Adding, changing or removing a user's subsidiary is much harder than it ought to be. Also there is no chance of enforcing data integrity i.e. validating that a subsidiary is valid against a reference table.
Maybe none of this matters to you. But there are very good reasons why Codd mandated "no repeating groups" as a criterion of First Normal Form, the foundation step of building a sound data model.
The correct solution, industry best practice for almost forty years, would be to recognise that SUBSIDIARY exists at a different granularity to CHANNEL and so should be stored in a separate table.
First of all sorry for my bad english, english is not my native language.
So people need to type "Barcode" and "Classroom"
But Barcode doesn't need to be inserted. The "ComputerID" that matches the given barcode needs to be inserted in "TblLocation" (As well as "Classroom")
But you cant use WHERE or ON in a INSERT INTO statement?
(It's for a web application, I'm programming with ASP.net and VB in visual studio. And i'm ussing an ms sql database.)
My 2 tables and form (example)
There is still something totally missing from your explanation. From the form you posted if you need to update it would be something like this.
update l
set Classroom = #Classroom
from tblLocation l
join tblComputers c on c.ComputerID = l.ComputerID
where c.Barcode = #Barcode
Of course if there is no row in either table this won't update anything.
The other part is the INSERT. IF there is a row in tblComputers already you could do something like this.
insert tblLocation
(
ComputerID
, Classroom
)
select #Classroom
, c.ComputerID
from tblComputers c
where c.Barcode = #Barcode
But what happens where there isn't a row in tblComputers? You would have to first create it right? There are so many holes in this still because you haven't provided any insight into your process. I hope the code I posted will at least get you started.
Not sure the best approach to do this, the application is older which is why I'm having so much trouble generating this. I read about doing a CASE statement but I don't have much SQL experience. Any help is appreciated and answers will be respected. Thanks. Also, there's no design to this, the people who wrote the application used placeholders and all the data comes form this huge file, which is beyond me. I don't know why because I've never seen anything like this. It's a monster.
'-
Dim TemplateColumnCDLExpiration As System.Web.UI.WebControls.TemplateColumn
TemplateColumnCDLExpiration = New System.Web.UI.WebControls.TemplateColumn
If Me.AllowSorting Then
TemplateColumnCDLExpiration.SortExpression = "CDLExpiration"
End If
TemplateColumnCDLExpiration.ItemTemplate =
New JAG.WebUI.Controls.IEditGridTemplate(ListItemType.Item,
"CDLExpiration",
JAG.WebUI.Controls.tEditGridItemControlType.Label)
TemplateColumnCDLExpiration.HeaderText = "CDL Expiration"
MyBase.Columns.Add(TemplateColumnCDLExpiration)
'-
OK, I'll give you the answer to your CASE question, but you have to promise that you'll read the considerations below. :)
I'm using Oracle SQL; I don't know if the syntax is different for other SQL implementations. Here's an example of a dummy query to show the syntax:
SELECT
CASE
WHEN (sysdate - TO_DATE('04/09/2013', 'mm/dd/yyyy') > 30) THEN 'red'
ELSE 'black'
END text_color
FROM dual;
The code in the parenthesis after the WHEN is the test. It compares the current date to April 9th and asks, "Is April 9th more than 30 days ago?" If so, it returns 'red' as the value of text_color. If that condition is false, it returns 'black'. Here's a more generalized form:
SELECT
CASE
WHEN (sysdate - :date_to_check > :expiration_days) THEN 'red'
ELSE 'black'
END text_color
FROM :my_table;
Considerations
You don't need this nasty piece of logic in SQL. The check for X number of days passing since the given date is not database logic. Fetching a date is database logic, deciding how many days have elapsed from that date until today could be argued as either DB logic or business logic, but deciding the text color is definitely display logic, meaning you should be modifying your .NET code, not your SQL. What happens if you need to change the display colors? The date check remains the same, but you have to modify...your SQL? SQL modifications should only need to happen if the data that is being retrieved or stored is modified. The bottom line is that this is not a clean separation of concerns.
SDL tridion doesn't provide any feature that helps getting report on mailing statistics for multiple publication in desired format. I am using following query (please ignore optimization of query) to get desired result but it is different than what is being shown on interface. For example I am getting 67 count for link accessed on interface where in DB it is 97 using following query. Seems I am missing some filters. Any pointer on what is missing here would be great.
/*DB Query*/
select e.EMAIL_LINK_URL, COUNT(e.EMAIL_LINK_URL) as maxcount
from Mailings a, EMAILS b, EMAILSTATUSES c, EMAILSTATUS_TYPES d, EMAIL_LINKURL e
where a.ID=b.MAILING_ID
and b.ID=c.EMAIL_ID
and c.STATUS_ID = d.ID
and c.EMAIL_LINK_ID = e.ID
and c.STATUS_ID = 5 (/*Status Type - 5 is for link accessed*/)
and a.ID = 2628 (/*Mailing ID*/)
group by e.EMAIL_LINK_URL
order by maxcount desc
Although writing your own, specific database query will likely perform better than querying the API for each Mailing -- you can easily miss stuff, as you found out. The queries done and the design of the database tables might also change without notice in future versions.
The API is future-proof and supported; direct database queries are not (although it's true that we usually don't fret read-only queries)
For the reasons mentioned above, I would suggest that anyone looking for this kind of information would first attempt it using the Audience Management API.