SSIS Format File - ssis

I have inherited a SSIS package which contains a bulk import task.
The bulk import tasks uses the following format file:
8.0
38
1 SQLCHAR 0 2 "" 1 branch_code Latin1_General_CI_AS
2 SQLCHAR 0 10 "" 2 sfkacct_number Latin1_General_CI_AS
3 SQLCHAR 0 3 "" 3 sfkacct_depot Latin1_General_CI_AS
4 SQLCHAR 0 35 "" 4 sfkacct_nominee_name Latin1_General_CI_AS
5 SQLCHAR 0 2 "" 5 sfkacct_domicile Latin1_General_CI_AS
6 SQLCHAR 0 3 "" 6 secore_transaction_status Latin1_General_CI_AS
7 SQLCHAR 0 11 "" 7 secore_transaction_reference Latin1_General_CI_AS
8 SQLCHAR 0 16 "" 8 customer_reference Latin1_General_CI_AS
9 SQLCHAR 0 35 "" 9 market_reference Latin1_General_CI_AS
10 SQLCHAR 0 35 "" 10 counterparty_reference Latin1_General_CI_AS
11 SQLCHAR 0 2 "" 11 transaction_type Latin1_General_CI_AS
12 SQLCHAR 0 18 "" 12 security_quantity Latin1_General_CI_AS
13 SQLCHAR 0 10 "" 13 security_code Latin1_General_CI_AS
14 SQLCHAR 0 12 "" 14 security_number Latin1_General_CI_AS
15 SQLCHAR 0 3 "" 15 security_group Latin1_General_CI_AS
16 SQLCHAR 0 8 "" 16 trade_date Latin1_General_CI_AS
17 SQLCHAR 0 8 "" 17 contractual_settlement_date Latin1_General_CI_AS
18 SQLCHAR 0 8 "" 18 actua1_settlement_date Latin1_General_CI_AS
19 SQLCHAR 0 8 "" 19 revised_date Latin1_General_CI_AS
20 SQLCHAR 0 3 "" 20 settlement_currency Latin1_General_CI_AS
21 SQLCHAR 0 20 "" 21 settlement_amount Latin1_General_CI_AS
22 SQLCHAR 0 3 "" 22 cash_currency Latin1_General_CI_AS
23 SQLCHAR 0 14 "" 23 cashacct_number Latin1_General_CI_AS
24 SQLCHAR 0 10 "" 24 broker_code Latin1_General_CI_AS
25 SQLCHAR 0 35 "" 25 broker_description Latin1_General_CI_AS
26 SQLCHAR 0 35 "" 26 beneficiary_code Latin1_General_CI_AS
27 SQLCHAR 0 35 "" 27 beneficiary_details1 Latin1_General_CI_AS
28 SQLCHAR 0 35 "" 28 beneficiary_details2 Latin1_General_CI_AS
29 SQLCHAR 0 35 "" 29 beneficiary_details3 Latin1_General_CI_AS
30 SQLCHAR 0 16 "" 30 failcode_org Latin1_General_CI_AS
31 SQLCHAR 0 16 "" 31 failcode_lst Latin1_General_CI_AS
32 SQLCHAR 0 35 "" 32 failcode_description Latin1_General_CI_AS
33 SQLCHAR 0 2 "" 33 status_code Latin1_General_CI_AS
34 SQLCHAR 0 8 "" 34 secore_transaction_inputdate Latin1_General_CI_AS
35 SQLCHAR 0 8 "" 35 secore_transaction_valuedate Latin1_General_CI_AS
36 SQLCHAR 0 6 "" 36 yearmonth Latin1_General_CI_AS
37 SQLCHAR 0 2 "" 37 domicile Latin1_General_CI_AS
38 SQLCHAR 0 1 "\r\n" 38 instruction_mode Latin1_General_CI_AS
Coudl anyone tell me what the 8.0 at the top of the file represents?

It is the version number of the bcp.
MSDN Link
It looks like
SQL Server 2000 - 8.0
SQL Server 2005 - 9.0
SQL Server 2008 - 10.0

Related

Timed out script

I'm using the following code in order to avoid using an IMPORTRANGE() formula. The data I'm getting is over 50k rows so that's why I'm using App Script.
But now I'm getting the following error:
Exception: Service Spreadsheets timed out while accessing document with id
function Live_Data_importing() {
var raw_live = SpreadsheetApp.openByUrl("someURL").getSheetByName("Sheet1");
var selected_columns = raw_live.getRange("A:Q").getValues().map(([a,,,,e,f,g,,i,j,,l,,n,o,]) => [a,e,f,g,i,j,l,n,o] );
var FF_filtered = selected_columns.filter(row=>row[8]=="somedata");
var FF_Hourly_live_data = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("somesheet");
FF_Hourly_live_data.getRange(2, 1, FF_filtered.length, FF_filtered[0].length).setValues(FF_filtered);
}
How can I fix this error? I also made a copy of the file but script is still running the same error.
Tested this on smaller set of data
It works okay
function Live_Data_importing() {
const ss = SpreadsheetApp.getActive();
var raw_live = ss.getSheetByName("Sheet3");
var selected_columns = raw_live.getRange("A1:Q" + raw_live.getLastRow()).getValues().map(([a, , , , e, f, g, , i, j, , l, , n, o,]) => [a, e, f, g, i, j, l, n, o]);//fix this range
var FF_filtered = selected_columns.filter(row => row[8] == 0);//My data is all integers
var FF_Hourly_live_data = ss.getSheetByName("Sheet4");//output sheet
FF_Hourly_live_data.getRange(2, 1, FF_filtered.length, FF_filtered[0].length).setValues(FF_filtered);
}
Data:
COL1
COL2
COL3
COL4
COL5
COL6
COL7
COL8
COL9
COL10
COL11
COL12
COL13
COL14
COL15
COL16
COL17
COL18
COL19
COL20
0
1
18
13
0
7
5
11
15
2
1
17
0
8
11
18
0
16
1
8
0
16
16
9
5
0
16
8
14
0
7
4
3
15
8
19
18
4
18
10
9
14
7
16
17
13
17
4
8
6
19
18
9
18
12
1
8
19
12
10
13
17
4
2
10
3
7
16
14
13
1
5
16
12
2
3
14
3
0
9
4
17
14
5
9
13
18
0
4
1
14
1
12
7
10
1
15
4
14
5
1
17
13
17
3
1
17
8
19
7
14
18
2
17
1
16
2
19
13
15
7
4
9
0
11
14
11
7
12
14
3
19
14
13
18
12
16
19
19
6
7
6
10
5
15
8
0
8
2
16
4
14
18
14
2
16
16
5
15
16
4
5
9
6
6
2
1
15
14
8
19
8
4
10
12
12
4
6
10
12
11
15
3
4
1
3
17
19
10
4
11
2
10
16
12
1
6
3
0
3
11
0
14
8
13
13
4
2
16
18
10
14
5
3
7
4
7
9
5
15
0
6
5
1
2
18
1
1
11
13
7
13
5
15
5
13
17
18
14
19
0
17
10
6
10
16
16
0
18
19
12
8
15
1
11
4
19
4
17
14
4
14
14
6
16
8
15
4
5
2
4
5
14
14
16
9
0
16
0
4
8
3
8
5
12
15
5
19
14
0
1
6
12
2
19
10
10
19
13
19
0
5
14
7
2
17
3
10
2
14
2
5
0
18
5
1
13
13
3
13
10
18
18
4
18
11
0
7
13
9
18
13
9
2
0
16
15
3
9
14
12
15
15
7
16
13
14
1
4
12
18
9
6
14
18
11
16
2
18
15
15
0
2
4
6
16
5
18
2
6
14
18
11
1
9
15
13
8
8
19
11
19
14
0
7
15
1
10
8
9
14
14
15
3
11
13
4
10
5
16

How to calculate percentage over multiple rows over group by

For the solution rate of some of our tickets I want to calculate the percentage of solved tickets in relation to the total number of tickets of the same type in the same month
I am able to get the number of solved tickets, but I am missing the total of all the tickets from the same type and the same month so always 0% or 100%.
Question= How can i cumulate the count of tickets so I can calculate percentage of solved tickets per month, type, status?
I've a group by on time, type AND status (see query below). So the total is always overruled by the group by of the status.
I've tried: cumulatives, roll up, pivot, union
SELECT date_format(st.createdDate,'%Y%m') createdAt,
count(st.id) COUNT,
st.typeId,
st.status,
sum(st.status2) status2,
sum(st.notStatus2) notStatus2,
((sum(st.status2)/sum(st.status2)+sum(st.notStatus2))*100) AS pct
FROM
(SELECT t.id,
t.added createdDate,
t.type_id typeId,
tt.name ticketType,
t.status,
if(t.status=2,1,0) AS status2,
if(t.status!=2,1,0) AS notStatus2,
datediff(closed,added) doorloopTijdDgn
FROM tickets t
JOIN ticket_types tt ON tt.id=t.type_id
WHERE added BETWEEN '2018-07-01' AND '2019-07-01' ) AS st #singletickets
GROUP BY createdAt,
ticketType,
status;
For the first two rows (type=62) I expect 33 out of 37 solved tickets = 89,2%
So "sum(st.status2)+sum(st.notStatus2)" of pct should be 37
Now I get:
createdAt count typeId status status2 notStatus2 pct
201807 33 62 2 33 0 100.0000
201807 4 62 6 0 4 NULL
201807 31 38 2 31 0 100.0000
201807 3 38 6 0 3 NULL
201807 15 12 2 15 0 100.0000
201807 11 11 2 11 0 100.0000
201807 1 48 2 1 0 100.0000
201807 19 30 2 19 0 100.0000
201807 5 9 2 5 0 100.0000
201807 12 33 2 12 0 100.0000
201807 1 52 2 1 0 100.0000
201807 2 45 2 2 0 100.0000
201807 41 58 2 41 0 100.0000
201807 3 58 6 0 3 NULL
201807 1 41 6 0 1 NULL
201807 1 13 2 1 0 100.0000
201807 35 66 2 35 0 100.0000
201807 8 20 2 8 0 100.0000
201807 1 20 4 0 1 NULL
201807 5 10 2 5 0 100.0000
201807 12 68 2 12 0 100.0000
201807 1 65 2 1 0 100.0000
201807 20 7 2 20 0 100.0000
201807 2 19 2 2 0 100.0000
201807 4 43 2 4 0 100.0000
201807 3 34 2 3 0 100.0000
201807 24 67 2 24 0 100.0000
201807 43 46 2 43 0 100.0000
201807 1 46 6 0 1 NULL
What I want:
createdAt count typeId status status2 notStatus2 pct
201807 33 62 2 33 0 89.2000
201807 4 62 6 0 4 0
201807 31 38 2 31 0 93.9000
201807 3 38 6 0 3 0
201807 15 12 2 15 0 100.0000
201807 11 11 2 11 0 100.0000
201807 1 48 2 1 0 100.0000
201807 19 30 2 19 0 100.0000
201807 5 9 2 5 0 100.0000
201807 12 33 2 12 0 100.0000
201807 1 52 2 1 0 100.0000
201807 2 45 2 2 0 100.0000
201807 41 58 2 41 0 93.2000
201807 3 58 6 0 3 0
201807 1 41 6 0 1 0
201807 1 13 2 1 0 100.0000
201807 35 66 2 35 0 100.0000
201807 8 20 2 8 0 88.8000
201807 1 20 4 0 1 0
I have mysql 5.7.12 to work with
seems you have wrong ()
should be
((sum(st.status2)/(sum(st.status2)+sum(st.notStatus2)))*100) as pct

Mysql find common values for all users

We are developing an local shop reccomendation system and in one of our sql queries we had a problem
We want to fetch the companies which all users in same cluster rated , but if any one of the users in the same group doesnt rated the company we wouldnt want to fetch it
SELECT ml_user_clusters.primaryUser,ml_user_clusters.clusterId,ml_ratings.companyId,ml_ratings.rating,ml_user_labels.groupId FROM ml_user_clusters
LEFT JOIN ml_ratings ON ml_ratings.userId = ml_user_clusters.primaryUser
LEFT JOIN ml_company_user_labels ON ml_company_user_labels.companyId = ml_ratings.companyId
LEFT JOIN ml_user_labels ON ml_user_labels.groupId = ml_company_user_labels.labelId
WHERE ml_user_clusters.clusterId = 0
We've started to add a query like in the below but couldnt able to finish it with proper AND clause
And our data is like in the below: So in the result we would like to have only the companies which has groupId=6 because all users in the same cluster(clusterId=0) rated a company with groupId = 6
primaryUser clusterId companyId rating groupId
497 0 135 5 NULL
498 0 135 10 NULL
79 0 135 12 NULL
501 0 135 10 NULL
79 0 85 14 2
79 0 8 4 5
79 0 98 11 5
79 0 3 5 5
497 0 6 7 6
500 0 6 7 6
499 0 29 7 6
497 0 29 7 6
499 0 77 7 6
500 0 29 7 6
498 0 6 7 6
500 0 77 11 6
500 0 130 3 6
498 0 130 3 6
501 0 77 19 6
499 0 6 7 6
79 0 30 1 7
500 0 30 7 7
79 0 48 7 9
79 0 39 1 13
79 0 48 7 13
499 0 6 7 15
497 0 6 7 15
79 0 8 4 15
500 0 6 7 15
79 0 98 11 15
498 0 6 7 15
79 0 3 5 15
79 0 81 7 15
79 0 3 5 17
79 0 82 7 17
79 0 103 7 17
79 0 118 3 17
79 0 63 3 17
501 0 118 7 17
79 0 82 7 19
79 0 118 3 19
79 0 63 3 19
501 0 118 7 19
79 0 39 1 21
79 0 85 14 23
Expected output must be: (Because all unique users in Cluster=0 has rated a company which has GroupID=6 )
primaryUser clusterId companyId rating groupId
497 0 6 7 6
500 0 6 7 6
499 0 29 7 6
497 0 29 7 6
499 0 77 7 6
500 0 29 7 6
498 0 6 7 6
500 0 77 11 6
500 0 130 3 6
498 0 130 3 6
501 0 77 19 6
499 0 6 7 6
Do you have any idea how we can fix that problem?
Something like this should work,you should build a fiddle for better testing.
Explanation: you count distinct users grouped by group id and compare with the total number of distinct users.If the two match it means all users in that respective groupid have voted.
SELECT ml_user_labels.groupId
FROM ml_user_clusters
LEFT JOIN ml_ratings ON ml_ratings.userId = ml_user_clusters.primaryUser
LEFT JOIN ml_company_user_labels ON ml_company_user_labels.companyId = ml_ratings.companyId
LEFT JOIN ml_user_labels ON ml_user_labels.groupId = ml_company_user_labels.labelId
WHERE ml_user_clusters.clusterId = 0
GROUP BY ml_user_labels.groupId
HAVING COUNT(DISTINCT ml_user_clusters.primaryUser) =
(SELECT COUNT(DISTINCT ml_user_clusters.primaryUser)
FROM ml_user_clusters
LEFT JOIN ml_ratings ON ml_ratings.userId = ml_user_clusters.primaryUser
LEFT JOIN ml_company_user_labels ON ml_company_user_labels.companyId = ml_ratings.companyId
LEFT JOIN ml_user_labels ON ml_user_labels.groupId = ml_company_user_labels.labelId
WHERE ml_user_clusters.clusterId = 0)x

SQL combine one column with another table and add new column

Sorry for the unclear title. But i want to make column editor_article which has name of editor. Only article with same value among id_article and parent_id have name of editor_article and editor_article has '0' value if id_section = 29 and if parent_id != 0. Editor_article got from editor column join with t_kolom.id_editor.
tbl_name:t_article
id_section id_article parent_id editor
29 441 0 2
33 1093 18 2
33 18 0 0
29 3144 0 8
30 3136 0 0
31 3130 0 0
31 3140 3130 22
31 3141 3130 335
30 3142 3136 546
tbl_name:t_kolom
id_editor name
1 john
2 gerrard
3 lukas
8 anthony
22 jimmy
335 eric
546 tyas
And the expected output:
id_section id_article parent_id editor editor_article
29 441 0 2 0
33 1093 18 2 0
33 18 0 0 gerrard
29 3144 0 8 0
30 3136 0 0 tyas
31 3130 0 0 jimmy,eric
31 3140 3130 22 0
31 3141 3130 335 0
30 3142 3136 546 0

Bulk import 0 Rows affected

When using the bulk insert command in SQL Server 2008 it returns:
(0 row(s) affected)
I am using this command to carry out the bulk insert:
BULK INSERT Test
FROM 'C:\DataFiles\Tests.dat'
WITH (FORMATFILE = 'C:\DataFiles\FormatFiles\TestFormat.Fmt');
GO
Tests.dat contains:
b00d23fe-580e-42dc-abd4-e8a054395126,48dd5dd6e3a144f7a817f234dd51469c,452eb8ce-6ae2-4e7a-a389-1097882c83ab,,, ,,,,Aria,,,160,,,86400,,2004-04-03 23:23:00.000,,2012-07-06 13:26:31.633,2012-07-06 13:27:44.650,3,,,,51B7A831-4731-4E2E-ACEC-06636ADC7AD3,,0,,0,,Field Name 1,,Field Name 2,,Field Name 3,,Field Name 4,
and the format file TestFormat.fmt contains:
9.0
39
1 SQLCHAR 0 37 "," 1 Key ""
2 SQLCHAR 0 37 "," 2 TestType ""
3 SQLCHAR 0 37 "," 3 CaseKey ""
4 SQLCHAR 0 30 "," 4 Height ""
5 SQLCHAR 0 30 "," 5 Weight ""
6 SQLCHAR 0 128 "," 6 PacemakerType Latin1_General_CI_AI
7 SQLCHAR 0 0 "," 7 Diary Latin1_General_CI_AI
8 SQLCHAR 0 0 "," 8 Indication Latin1_General_CI_AI
9 SQLCHAR 0 0 "," 9 Medication Latin1_General_CI_AI
10 SQLCHAR 0 37 "," 10 RecorderType ""
11 SQLCHAR 0 100 "," 11 RecorderSerial Latin1_General_CI_AI
12 SQLCHAR 0 0 "," 12 Comments Latin1_General_CI_AI
13 SQLCHAR 0 12 "," 13 Status ""
14 SQLCHAR 0 0 "," 14 AdditionalData Latin1_General_CI_AI
15 SQLCHAR 0 37 "," 15 OrderKey ""
16 SQLCHAR 0 12 "," 16 Duration ""
17 SQLCHAR 0 12 "," 17 Age ""
18 SQLCHAR 0 24 "," 18 RecordingStartDateTime ""
19 SQLCHAR 0 128 "," 19 Ward Latin1_General_CI_AI
20 SQLCHAR 0 24 "," 20 CreatedDateTime ""
21 SQLCHAR 0 24 "," 21 UpdatedDateTime ""
22 SQLCHAR 0 21 "," 22 UserGroupBits ""
23 SQLCHAR 0 24 "," 23 LastArchive ""
24 SQLCHAR 0 128 "," 24 PointOfCare Latin1_General_CI_AI
25 SQLCHAR 0 128 "," 25 Bed Latin1_General_CI_AI
26 SQLCHAR 0 37 "," 26 DownloadFacilityKey ""
27 SQLCHAR 0 37 "," 27 AnalysisFacilityKey ""
28 SQLCHAR 0 12 "," 28 Priority ""
29 SQLCHAR 0 37 "," 29 FacilityKey ""
30 SQLCHAR 0 12 "," 30 PacemakerTypeStandard ""
31 SQLCHAR 0 128 "," 31 TestTypeName Latin1_General_CI_AI
32 SQLCHAR 0 128 "," 32 UserDefined1Name Latin1_General_CI_AI
33 SQLCHAR 0 128 "," 33 UserDefined1Value Latin1_General_CI_AI
34 SQLCHAR 0 128 "," 34 UserDefined2Name Latin1_General_CI_AI
35 SQLCHAR 0 128 "," 35 UserDefined2Value Latin1_General_CI_AI
36 SQLCHAR 0 128 "," 36 UserDefined3Name Latin1_General_CI_AI
37 SQLCHAR 0 128 "," 37 UserDefined3Value Latin1_General_CI_AI
38 SQLCHAR 0 128 "," 38 UserDefined4Name Latin1_General_CI_AI
39 SQLCHAR 0 128 "\r\n" 39 UserDefined4Value Latin1_General_CI_AI
I cannot figure out why this isn't working. Other people have had similar problems because they had more fields and actual columns in their database. Or using .csv files which are not supported apparently.
This works fine on every other table in the database I am importing with no errors so I can't understand why it doesn't work here.
Any help would be greatly appreciated!
Thanks