Bulk import 0 Rows affected - sql-server-2008

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

Related

An sdf file that I produce doesn't get accepted by a converter

I made a program that converts csv files into sdf files. Those files were supposed to go in another converter that turns them into something called a "Nist MS Library". The problem is that my file doesn't get accepted by the converter for "No spectra have been converted" and I don't understand why.
The files seem identical to me and I think I'm missing something about the specific file extension.
I'm really sorry if this doesn't belong here, I will delete the post if this is the case, but I really do not know where to ask.
I tried to make the "mass spectral peaks" integer, floats, delete them and put some values that I knew for sure that were accepted by the Nist converter, but nothing seems to work.
I will put 2 molecules, the first one is mine, the one that doesn't get accepted, the other one is the one that is fine for the program.
Coumarin
No Structure
0 0 0 0 0 0 0 0 0 0 0
> <NAME>
Coumarin
> <INCHIKEY>
> <FORMULA>
> <MW>
> <CASNO>
91645
> <ID>
2
> <COMMENT>
SAFC Cat. n. W526509\nColumn: SLB-5ms part#28471-U; Supelcowax-10 part#24079; Equity-1 part#28046-U;\nwww.sigmaaldrich.com |RI:1438|
> <SYNONYMS>
Coumarin
> <NUM PEAKS>
140
> <MASS SPECTRAL PEAKS>
39 1
39 233
40 38
40 0
40 0
41 0
41 1
41 5
42 2
42 2
43 35
43 0
43 12
44 26
45 20
45 67
46 7
46 4
46 2
46 1
47 0
48 4
49 32
49 3
50 5
50 166
51 183
52 20
53 35
54 7
55 1
56 0
58 0
59 2
59 23
60 6
60 11
61 89
62 213
63 503
64 164
64 13
65 15
65 7
66 9
68 4
71 0
71 1
72 2
73 1
73 19
74 0
74 32
75 39
76 14
77 11
77 1
78 0
78 0
79 0
79 9
79 0
80 2
80 1
81 0
81 0
81 1
82 0
82 0
83 0
83 0
84 6
84 0
85 17
86 2
86 2
87 28
88 7
89 523
90 581
91 25
91 48
92 40
92 36
93 4
93 5
94 1
94 0
97 2
98 6
98 0
99 2
99 0
100 0
100 1
101 5
102 3
103 0
103 0
103 0
104 0
105 0
105 0
106 0
106 0
106 0
107 0
108 0
109 0
110 0
110 0
111 0
111 0
112 0
112 0
113 0
116 0
117 6
117 0
118 1000
119 94
120 34
120 10
121 4
121 0
122 0
122 0
131 0
135 0
145 1
146 0
146 547
147 58
148 5
183 0
246 0
334 0
351 0
359 0
382 0
> <RI value>
1430.1
$$$$
ETHYL HYDROSULFIDE
(C) 2015 John Wiley & Sons, Inc.
CAS rn = 75081, Library ID = 1
3 2 0 0 0 0 0 0 0 0999 V2000
0.0000 0.2061 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.7146 -0.2061 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
-0.7146 -0.2061 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 1 0 0 0 0
M END
> <NAME>
Ethyl hydrosulfide
> <SYNONYMS>
Ethanethiol
$:28DNJIEGIFACGWOD-UHFFFAOYSA-N
$:29n=703/0/1 p=620/0/1
> <FORMULA>
C2H6S
> <MW>
62
> <CASNO>
75081
> <ID>
1
> <COMMENT>
WileyID="LM_FFNSC3_1" RI1="703 (SLB-5MS (Hydro))" RI2="392 (SLB-5MS (FAMEs))" RI3="620 (Supelcowax-10 (FAMEs)" RI4="568 (Supelcowax-10 (FAEEs)" Contributor="Prof. L. Mondello (Chromaleont s.r.l./Univ. Messina, Italy)"
> <NUM PEAKS>
21
> <MASS SPECTRAL PEAKS>
44 20
45 235
46 147
47 727
48 20
49 32
50 2
51 2
52 2
53 2
54 2
55 2
56 16
57 84
58 115
59 84
60 16
61 155
62 999
63 36
64 44
$$$$

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

Insert php multiple data into mysql

I have 1000+ customers. I require customer report.
Here debit = potato + onion + ginger. Credit is commission.Balance will be updated every time. It will be balance - debit and balance + credit alternatively.
Grocery data report is as: Data is filled through php form with mysql_fetch_array query. Here few customers are as sample. and few data fields.
id cus_id cus_name potato onion ginger debit credit balance
1 12 munna 10 25 28 63 0 37
2 16 anil 24 56 84 164 0 136
3 34 palash 17 47 51 115 0 85
4 45 dimpy 35 64 39 138 0 112
Table grocery before and after entering new data:
id cus_id cus_name potato onion ginger debit credit balance
1 12 munna 10 25 28 63 0 37
2 16 anil 24 56 84 164 0 136
3 34 palash 17 47 51 115 0 85
4 45 dimpy 35 64 39 138 0 112
5 12 munna 0 0 0 0 6 43
6 16 anil 0 0 0 0 16 152
7 34 palash 0 0 0 0 12 97
8 45 dimpy 0 0 0 0 14 126
My problem is :
I am unable to update balance column, cus_name wise and cus_id wise and insert all data into mysql database. Suggest me with mysql query.

SQL Server Bulk Import with format file - An unexpected end of file was encountered in the data file

I am testing bulk import from a comma separated csv file to sql server 2012. for this purpose i have created the format file by using BCP utility.
following is the a single row from csv file
W42031535,4000111689,Domestic,NOV-DEC 2014,Mustafa Satta S/O Abdul Sattar,"H#31, Block#F, TNT Colony",1-Dec-14,17-Dec-14,0,322,20,342,8380,0,8722,32,8754,"JUL-AUG,14",0,"SEP-OCT,14",0,"NOV-DEC,14",0,8,242,161,0,0,0,NULL,NULL,NULL,NULL,0
and following is my format file, generated by using BCP utility
11.0
34
1 SQLNCHAR 0 100 '","' 1 AccountNo SQL_Latin1_General_CP1_CI_AS
2 SQLNCHAR 0 100 '","' 2 BillNo SQL_Latin1_General_CP1_CI_AS
3 SQLNCHAR 0 100 '","' 3 Category SQL_Latin1_General_CP1_CI_AS
4 SQLNCHAR 0 100 '","' 4 Billing_Period SQL_Latin1_General_CP1_CI_AS
5 SQLNCHAR 0 200 '","' 5 Name SQL_Latin1_General_CP1_CI_AS
6 SQLNCHAR 0 0 '","' 6 Address SQL_Latin1_General_CP1_CI_AS
7 SQLNCHAR 0 100 '","' 7 Issue_Date SQL_Latin1_General_CP1_CI_AS
8 SQLNCHAR 0 100 '","' 8 Due_Date SQL_Latin1_General_CP1_CI_AS
9 SQLDECIMAL 0 19 '","' 9 Water_Bill Decimal
10 SQLDECIMAL 0 19 '","' 10 Sewerage_Bill Decimal
11 SQLDECIMAL 0 19 '","' 11 Aquifer_Charges Decimal
12 SQLDECIMAL 0 19 '","' 12 Current_Amount Decimal
13 SQLDECIMAL 0 19 '","' 13 Arrears Decimal
14 SQLDECIMAL 0 19 '","' 14 Service_Charges Decimal
15 SQLDECIMAL 0 19 '","' 15 Payable_within_DueDate Decimal
16 SQLDECIMAL 0 19 '","' 16 Surcharge Decimal
17 SQLDECIMAL 0 19 '","' 17 Payable_after_DueDate Decimal
18 SQLNCHAR 0 100 '","' 18 Payment_History_1 SQL_Latin1_General_CP1_CI_AS
19 SQLDECIMAL 0 19 '","' 19 Paid_1 Decimal
20 SQLNCHAR 0 100 '","' 20 Payment_History_2 SQL_Latin1_General_CP1_CI_AS
21 SQLDECIMAL 0 19 '","' 21 Paid_2 Decimal
22 SQLNCHAR 0 100 '","' 22 Payment_History_3 SQL_Latin1_General_CP1_CI_AS
23 SQLDECIMAL 0 19 '","' 23 Paid_3 Decimal
24 SQLDECIMAL 0 19 '","' 24 Area Decimal
25 SQLDECIMAL 0 19 '","' 25 Water_Rate Decimal
26 SQLDECIMAL 0 19 '","' 26 Sewerage_Rate Decimal
27 SQLDECIMAL 0 19 '","' 27 Discharge_Basis Decimal
28 SQLNCHAR 0 100 '","' 28 Pump_Size SQL_Latin1_General_CP1_CI_AS
29 SQLDECIMAL 0 19 '","' 29 Ferrule_Size Decimal
30 SQLNCHAR 0 100 '","' 30 Meter_Type SQL_Latin1_General_CP1_CI_AS
31 SQLNCHAR 0 100 '","' 31 Meter_Status SQL_Latin1_General_CP1_CI_AS
32 SQLNCHAR 0 100 '","' 32 Last_Readin SQL_Latin1_General_CP1_CI_AS
33 SQLNCHAR 0 100 '","' 33 Current_Reading SQL_Latin1_General_CP1_CI_AS
34 SQLDECIMAL 0 19 "\n" 34 Water_Aquiffer_Charges Decimal
and here is the SQL
BULK INSERT WASA_Bill_Detail
FROM 'e:\WasaBillRecord.csv'
WITH
(
KEEPIDENTITY,
FORMATFILE = 'e:\bill_detail_format1.fmt',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
ERRORFILE = 'e:\error.log'
)
know when i execute the abve sql following error accour
Msg 4832, Level 16, State 1, Procedure BInsert, Line 10
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Procedure BInsert, Line 10
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Procedure BInsert, Line 10
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
i have tried ROWTERMINATOR = '\n', , ROWTERMINATOR = '\r\n', and ROWTERMINATOR = '0x0a',. The error is same
any help
From the BULK INSERT doc under examples:
C. Using line feed as a row terminator
The following example imports a file that uses the line feed as a row terminator such as a UNIX output:
DECLARE #bulk_cmd varchar(1000);
SET #bulk_cmd = 'BULK INSERT AdventureWorks2012.Sales.SalesOrderDetail
FROM ''<drive>:\<path>\<filename>''
WITH (ROWTERMINATOR = '''+CHAR(10)+''')';
EXEC(#bulk_cmd);
Due to how Microsoft Windows treats text files (\n automatically gets replaced with \r\n).
Alternately, send your text file through a line ending converter (unix2dos, et al) or transfer the file in ASCII mode from whatever server you retrieve it from.

SSIS Format File

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