Strange results of Indexing services - sql-server

Currently I am working on Indexing services to search document from Windows server. I am using following Query to search "F-0350"
Query
Select rank,Filename,Size,HitCount from Scope() where CONTAINS(Contents, 'ISABOUT('F-0350' WEIGHT(1.0))')
Query Result:
Rank FileName Size HitCount
572 sf ob-0350.prod.xml 2521 4
572 sf g-0350.prod.xml 1199 4
572 sf qa-0350.prod.xml 1864 4
572 sf f-0350.prod.xml 1551 4
362 sf ob-0353.prod.xml 2469 4
I am expecting 4th record on top but its not coming.

Related

I want a record of the first day of each month

SQL makes it easy to create certain For example, if you want to retrieve only the first of the month (not necessarily the '1st day' of the month) from the data accumulated in a daily batch for labels in a graph.
recorded_date
2022-09-05
2022-10-03
2022-11-01
2022-12-01
2023-01-03
-- collect from mysql
select min(recorded_date) recorded_date from daily_table group by DATE_FORMAT(`recorded_date`, "%Y-%m")
On the other hand, queryset requires that 'values' be specified before aggregation.
first_days = Industry.objects\
.values('recorded_date')\
.annotate(ym=Func(F('recorded_date'), Value('%Y%m'), function='DATE_FORMAT', output_field=CharField()))\
.annotate(count=Count('id'))
The queryset is written out as follows
SELECT
`vietnam_research_industry`.`recorded_date`,
DATE_FORMAT(`vietnam_research_industry`.`recorded_date`, '%Y%m') AS `ym`,
COUNT(`vietnam_research_industry`.`id`) AS `count`
FROM `vietnam_research_industry`
GROUP BY `vietnam_research_industry`.`recorded_date`, DATE_FORMAT(`vietnam_research_industry`.`recorded_date`, '%Y%m')
ORDER BY NULL
this is failed as follows
recorded_date
ym
count
2022-12-16
202212
757
2022-12-21
202212
757
2022-12-22
202212
757
2022-12-23
202212
757
2022-12-26
202212
757
2022-12-27
202212
757
2022-12-28
202212
757
2022-12-29
202212
757
2022-12-30
202212
757
Is there no choice but to use 'raw' in these cases?
Currently, all dates are retrieved without duplicates with 'distinct' and handled by setdefault in the dictionary object.
thanks :)
You can try below query for the same.
Industry.objects\
.annotate(month=ExtractMonth("recorded_date"), year=ExtractYear("recorded_date"), concat=Concat("month", Value("-"), "year", output_field=CharField()))\
.values('concat')\
.annotate(Min("recorded_date"))\
.values("recorded_date__min")
Let me know if it helps :)

SQL recursive get BOM from PSP

I am having a MS SQL Server (2016) and a database which contains i.a. table like this : (it´s a view created in an Autodesk PSP Database - please don´t ask why ... :-) )
CHILD_AIMKEY
QUANTITY
PARENT_AIMKEY
StatusOfParent
StatusOfChild
5706657
1
5664344
100
103
5706745
1
5664344
100
103
5707104
1
5664344
100
103
5707109
1
5664344
100
100
5801062
1
5664344
100
103
The "children" can contain other "children" and in that case they would be their "parents".
So it´s a standard structured BOM table from a CAD PDM System.
If I do the following "Select Statement" I get all the children of the top level parent:
SELECT [CHILD_AIMKEY] , [POSITION], [QUANTITY] ,[PARENT_AIMKEY],[StatusOfParent],[StatusChild] FROM database_table where Parent_aimkey = '5664344'
(as shown in the table above)
My first question is : How to recursivly process all children of each parent from that table ? (Could be an other table or direct output)
The format should be: Parent_Aimkey, Child_Aimkey, Quantity
The second question is a bit more complicated:
I try it with some "pseudo code":
If Tree_Level_of_DIRECT_Parent < 3 then show CHILD_AIMKEY,QUANTITY in queryresult_above
If Tree_Level_of_DIRECT_Parent > 2 and StatusOf_DIRECT_Parent = 103 and StatusOf_DIRECT_Child = 103 then show CHILD_AIMKEY,QUANTITY in queryresult_above
Is that in some way possible ? (If there is a need to extend the database view of an other field or another table, that´s no problem)
I know this looks a bit confusing, but what I need is the Autodesk Inventor structured BOM in an SQL Statement or stored procedure.
Any would be really much appreciated
Thanks
Alex.

Email sql query results of multiple email addresses daily

I am fairly green at SQL and have reached a road block. I have a Job that already runs a query and sends an email to our purchasing department agents via the agent.
Here is my sample data they receive as a text attachment:
po_num vend_num qty_needed external_email_addr
318 1 200 email#earthlink.net
318 1 910 email#earthlink.net
703 2 250 email#row.com
993 3 3600 email#cast.com
993 3 3600 email#cast.com
676 4 1 NULL
884 5 10000 email#Futures.com
118 5 2500 email#Futures.com
My goal is to automatically send each vendor one email of the qty_needed using the email address in external_email_addr field. Also, if the email address is NULL it would send me an email that this needs to be fixed.
I am not sure how complicated or simple this is but any help would be greatly appreciated.
Since the po_num is unique you will generate several mails per email address per day based on the example data you provided.
I dont have access to SQL at the moment so the syntax might need some sprucing up.
SELECT po_num,
vend_num,
qty_needed,
CASE WHEN external_email_addr ='' THEN COALESCE(external_email_addr,'defaultempty#fixthisproblem.com') ELSE external_email_ddr END AS email_address
FROM table_name

how to run on an imported table and pass each row as a parameter to a query(SQL server)

I have a CSV file that I load into my DB( Without using SSIS) with about 20 rows and 3 columns(as below):
**start_date_local** **end_date_local** **provider_unit**
18/04/2017 16:00 19/04/2017 16:00 501638-52973
19/04/2017 05:30 19/04/2017 23:00 501613-52345
07/04/2017 14:30 08/04/2017 15:30 201447-20266
each row/record should act as a parameter in my query (SQL server) that consist the following 'Where' clause
((Transmission.Transmission_StartDateAccurate >= '**start_date_local**')
AND (Transmission.Transmission_EndDateAccurate <= **'end_date_local'**))
AND Units.sn LIKE **'provider_unit'**
i would like to receive at my result set usage data (Which is in another table and that's fine) of each unit at its specific times - as follows:
start_date_local end_date_local provider_unit GB USAGE
18/04/2017 16:00 19/04/2017 16:00 501638-52973 35.3
19/04/2017 05:30 19/04/2017 23:00 501613-52345 42.4
07/04/2017 14:30 08/04/2017 15:30 201447-20266 4.5
please advice:)
Thanks,
Guy
If you are loading this data into a Staging table within your database, you can just join onto it to use the data in a set based manner, which will return your dataset for all instances.
Not having your full schema this is a bit of guess work, but you should be doing something like this:
select s.start_date_local
,s.end_date_local
,s.provider_unit
,t.GBUsage
from Transmission t
join StagingTable s
on(t.Transmission_StartDateAccurate >= s.start_date_local
and t.Transmission_EndDateAccurate <= s.end_date_local
)
join Units u
on(u.sn like s.provider_unit);

SQL Server - Database size numbers don't add up

I'm using the query from this QA, verbatim, to get a size report of all of the tables in my database ( Get size of all tables in database )
When I run it, I get these values in the TotalSpaceKB column:
TableName | RowCounts | TotalSpaceKB
Accounts 116507 27040
Calls 9687278 3903176
Categories 13 16
Clients 9 16
CountryCosts 14 16
CreditTransactions 218664 41200
DoNotCallList 40282 6120
Hosts 2166947 190080
MoneyTransactions 3907 464
PayPalIpns 3907 1880
Products 402 216
ProductsInCategories 263 16
Queries 15 32
QueryParameters 15 16
Settings 26 16
Sites 9 16
Templates 65 56
Sum of TotalSpaceKB is 4,170,376 KB: 4GB
But when I go SSMS > Database > Properties > General > Size > 37795.25 MB : 37GB
I don't have filesystem access so I can't get the exact file sizes. But why the discrepancy?
Yes, the missing bit is the transaction log. What is shown in the properties window is the total size of all files that are used by a database. The query you used measures only the size of data but not the transaction log.

Resources