How to handle bad data quality in a SQL query - sql-server-2008
The code below is a sample of grouped data containing Temperature (bear in mind it's temperature taken of a human being in hospital) from our source system.
Obviously the data is horrible but wondered if it was possible to somehow turn this data into and INT as we have a UOM (Unit of measure) field so we only need the number.
Data issues:
88 degree is obviously Fahrenheit and not Celsius
3635 would be 36.35
.368 would be 36.8
37.3. would be 37.3
.37.7 would be 37.7
377 would be 37.7
.3.8 would be 38
I think any other variation should just be excluded invalid data to be fair as cannot accurately make an informed assumption.
DECLARE #Test TABLE (
[Temperature] VARCHAR(500),
[Count] VARCHAR(50)
)
INSERT INTO #Test ([Temperature],[Count])
VALUES
('34.4 oC',' 9 '),
('36.02 oC',' 1 '),
('36.36 oC',' 3 '),
('36.5 oC',' 5593 '),
('36.5. oC',' 1 '),
('36.6. oC',' 2 '),
('36.74 oC',' 2 '),
('36.82 oC',' 2 '),
('37.36 oC',' 2 '),
('37.49 oC',' 4 '),
('40 oC',' 1 '),
('88 oC',' 1 '),
(' 3635 oC',' 1 '),
(' .368 oC',' 1 '),
('33.5 oC',' 1 '),
('35.2 oC',' 84 '),
('35.20 oC',' 1 '),
('35.99 oC',' 1 '),
('36.35 oC',' 2 '),
('37.3. oC',' 1 '),
('39.5 oC',' 5 '),
('86 oC',' 1 '),
(' 356 oC',' 12 '),
(' 364 oC',' 72 '),
(' 379 oC',' 9 '),
(' 385 oC',' 2 '),
(' 3535 oC',' 1 '),
(' .37.7 oC',' 1 '),
('35.5 oC',' 290 '),
('35.87 oC',' 1 '),
('36..6 oC',' 1 '),
('36.25 oC',' 2 '),
('36.45 oC',' 2 '),
('36.62 oC',' 2 '),
('36.68 oC',' 5 '),
('36.8. oC',' 2 '),
('37.03 oC',' 5 '),
('37.1 oC',' 3610 '),
('37.16 oC',' 3 '),
('37.2 oCC000715799',' 1 '),
('37.27 oC',' 2 '),
('37.91 oC',' 1 '),
('38.9 oC',' 28 '),
('63.5 oC',' 1 '),
('71 oC',' 1 '),
(' 377 oC',' 8 '),
(' 36.5 oC',' 1 '),
(' 3.4 oC',' 3 '),
(' 3.7 oC',' 3 '),
('36.59 oC',' 1 '),
('36.67 oC',' 5 '),
('37.13 oC',' 1 '),
('37.18 oC',' 1 '),
('37.24 oC',' 1 '),
('39.7 oC',' 5 '),
('76 oC',' 2 '),
('80 oC',' 2 '),
(' 347 oC',' 1 '),
(' 352 oC',' 2 '),
(' 368 oC',' 64 '),
(' 3602 oC',' 1 '),
(' 3688 oC',' 1 '),
(' .36.4 oC',' 1 '),
(' .8 oC',' 1 '),
(' 3.2 oC',' 2 '),
('34.3 oC',' 5 '),
('34.9 oC',' 20 '),
('35 oC',' 124 '),
('35.81 oC',' 1 '),
('36.17 oC',' 2 '),
('36.23 oC',' 1 '),
('36.37 oC',' 2 '),
('36.38 oC',' 4 '),
('36.42 oC',' 1 '),
('36.76 oC',' 2 '),
('37..2 oC',' 1 '),
('37.00 oC',' 4 '),
('37.07 oC',' 6 '),
('37.12 oC',' 2 '),
('37.2 oC',' 3151 '),
('37.48 oC',' 2 '),
('39. oC',' 1 '),
('39.2 oC',' 9 '),
('39.9 oC',' 2 '),
(' 370 oC',' 1 '),
('30.1 oC',' 1 '),
('34.1 oC',' 2 '),
('34.8 oC',' 17 '),
('35.43 oC',' 1 '),
('36..8 oC',' 2 '),
('36.05 oC',' 1 '),
('36.21 oC',' 4 '),
('36.31 oC',' 2 '),
('36.41 oC',' 1 '),
('36.58 oC',' 8 '),
('36.8 oC',' 8134 '),
('36.81 oC',' 3 '),
('36.88 oC',' 2 '),
('36.89 oC',' 2 '),
('36.99 oC',' 4 '),
('37.01 oC',' 6 '),
('37.14 oC',' 3 '),
('37.33 oC',' 1 '),
('37.37 oC',' 6 '),
('37.44 oC',' 1 '),
('37.59 oC',' 2 '),
('38.5 oC',' 85 '),
('39.4 oC',' 9 '),
('78 oC',' 2 '),
('92 oC',' 1 '),
(' 361 oC',' 19 '),
(' 383 oC',' 1 '),
(' 391 oC',' 1 '),
(' 3642 oC',' 1 '),
(' 3699 oC',' 2 '),
(' 37.6 oC',' 1 '),
('35.59 oC',' 1 '),
('35.69 oC',' 1 '),
('35.90 oC',' 1 '),
('36..9 oC',' 1 '),
('36.08 oC',' 2 '),
('36.27 oC',' 1 '),
('36.365 oC',' 1 '),
('36.51 oC',' 1 '),
('36.78 oC',' 4 '),
('36.84 oC',' 1 '),
('36.85 oC',' 3 '),
('36.97 oC',' 2 '),
('37.29 oC',' 1 '),
('37.3 oC',' 2306 '),
('37.8 oC',' 730 '),
('38.08 oC',' 1 '),
('38.4 oC',' 113 '),
('38.49 oC',' 1 '),
('38.7 oC',' 53 '),
('39.3 oC',' 10 '),
('70 oC',' 2 '),
(' 357 oC',' 5 '),
(' 362 oC',' 49 '),
(' 396.8 oC',' 1 '),
(' 3700 oC',' 1 '),
(' 3752 oC',' 1 '),
(' .381 oC',' 1 '),
(' 0.37 oC',' 1 '),
(' 3.1 oC',' 1 '),
('14 oC',' 1 '),
('27 oC',' 1 '),
('34.2 oC',' 5 '),
('34.5 oC',' 22 '),
('35.9 oC',' 633 '),
('36.44 oC',' 2 '),
('36.57 oC',' 1 '),
('36.65 oC',' 1 '),
('36.66 oC',' 3 '),
('37.04 oC',' 7 '),
('65.9 oC',' 1 '),
('82 oC',' 2 '),
(' 118 oC',' 1 '),
(' 358 oC',' 6 '),
(' 381 oC',' 2 '),
(' 396.6 oC',' 1 '),
(' 3704 oC',' 1 '),
(' 3801 oC',' 1 '),
(' ',' 195340 '),
(' 362 oC',' 1 '),
(' .374 oC',' 1 '),
(' 3.6 oC',' 3 '),
('26.5 oC',' 1 '),
('35.0 oC',' 28 '),
('35.79 oC',' 1 '),
('36..7 oC',' 1 '),
('36.00 oC',' 2 '),
('36.18 oC',' 1 '),
('36.48 oC',' 4 '),
('36.49 oC',' 3 '),
('37.19 oC',' 2 '),
('37.46 oC',' 1 '),
('37.9 oC',' 465 '),
('38.12 oC',' 1 '),
('39 oC',' 25 '),
(' 351 oC',' 2 '),
(' 369. oC',' 1 '),
(' 389 oC',' 1 '),
(' 3736 oC',' 1 '),
(' NULL ',' 7 '),
('35.98 oC',' 1 '),
('36 oC',' 2948 '),
('36.28 oC',' 1 '),
('36.69 oC',' 1 '),
('36.72 oC',' 2 '),
('36.77 oC',' 4 '),
('36.98 oC',' 7 '),
('37.05 oC',' 3 '),
('37.06 oC',' 2 '),
('37.15 oC',' 3 '),
('37.25 oC',' 5 '),
('37.26 oC',' 3 '),
('37.39 oC',' 3 '),
('37.42 oC',' 1 '),
('37.68 oC',' 3 '),
('38.3 oC',' 160 '),
('38.6. oC',' 1 '),
(' 376 oC',' 18 '),
(' 3617 oC',' 1 '),
(' 3703 oC',' 1 '),
(' 3.8 oC',' 2 '),
(' 7.6 oC',' 1 '),
('30.6 oC',' 1 '),
('34 oC',' 3 '),
('34.7 oC',' 9 '),
('35.06 oC',' 1 '),
('35.7 oC',' 324 '),
('35.74 oC',' 1 '),
('36.01 oC',' 2 '),
('36.1 oC',' 1517 '),
('36.12 oC',' 1 '),
('36.4 oC',' 5001 '),
('36.6 oC',' 7044 '),
('36.79 oC',' 5 '),
('36.86 oC',' 1 '),
('36.90 oC',' 1 '),
('36.93 oC',' 1 '),
('37.30 oC',' 1 '),
('37.92 oC',' 1 '),
('38. oC',' 5 '),
('38.6 oC',' 65 '),
('38.8 oC',' 46 '),
('97 oC',' 1 '),
(' 354 oC',' 4 '),
(' 355 oC',' 5 '),
(' 365 oC',' 107 '),
(' 3654 oC',' 1 '),
('35.8 oC',' 495 '),
('36.09 oC',' 6 '),
('36.2 oC',' 2526 '),
('36.3. oC',' 1 '),
('36.47 oC',' 1 '),
('36.53 oC',' 2 '),
('36.9 oC',' 5449 '),
('37.0 oC',' 1209 '),
('37.1. oC',' 1 '),
('37.32 oC',' 2 '),
('37.38 oC',' 5 '),
('37.45 oC',' 1 '),
('37.5 oC',' 1477 '),
('37.6 oC',' 1101 '),
('37.80 oC',' 1 '),
('38.1 oC',' 215 '),
('40.2 oC',' 1 '),
('62 oC',' 1 '),
(' 366 oC',' 61 '),
(' 375 oC',' 28 '),
('16 oC',' 1 '),
('34.0 oC',' 1 '),
('35. oC',' 3 '),
('35.1 oC',' 61 '),
('35.23 oC',' 1 '),
('35.58 oC',' 2 '),
('36. oC',' 59 '),
('36.03 oC',' 1 '),
('36.16 oC',' 2 '),
('36.94 oC',' 2 '),
('37.08 oC',' 7 '),
('37.21 oC',' 1 '),
('37.47 oC',' 1 '),
('39.8 oC',' 3 '),
(' 346 oC',' 1 '),
(' 353 oC',' 2 '),
(' 369 oC',' 57 '),
(' 374 oC',' 28 '),
(' 3677 oC',' 1 '),
(' 37.4 oC',' 1 '),
('34.6 oC',' 15 '),
('35.3 oC',' 74 '),
('35.4 oC',' 120 '),
('35.6 oC',' 320 '),
('36.06 oC',' 1 '),
('36.07 oC',' 2 '),
('36.14 oC',' 1 '),
('36.19 oC',' 1 '),
('36.54 oC',' 1 '),
('36.71 oC',' 1 '),
('36.92 oC',' 1 '),
('37.50 oC',' 1 '),
('37.54 oC',' 1 '),
('37.7 oC',' 836 '),
('39.0 oC',' 8 '),
('39.6 oC',' 3 '),
('60 oC',' 1 '),
(' 127 oC',' 1 '),
(' 336.8 oC',' 1 '),
(' 1500 oC',' 1 '),
(' 36.4 oC',' 1 '),
('36.0 oC',' 829 '),
('36.3 oC',' 3192 '),
('36.56 oC',' 3 '),
('36.63 oC',' 2 '),
('36.7 oC',' 6348 '),
('36.73 oC',' 3 '),
('36.96 oC',' 4 '),
('37. oC',' 64 '),
('37.4 oC',' 1861 '),
('37.69 oC',' 1 '),
('38.01 oC',' 1 '),
('93 oC',' 1 '),
(' 351. oC',' 1 '),
(' 371 oC',' 24 '),
(' 372 oC',' 45 '),
(' 373 oC',' 30 '),
(' 3722 oC',' 1 '),
(' .3.8 oC',' 1 '),
('26.1 oC',' 1 '),
('35.97 oC',' 4 '),
('36.61 oC',' 3 '),
('37 oC',' 4890 '),
('37.02 oC',' 3 '),
('37.66 oC',' 1 '),
('38 oC',' 367 '),
('38.0 oC',' 72 '),
('38.2 oC',' 225 '),
('39.1 oC',' 22 '),
(' 359 oC',' 14 '),
(' 360 oC',' 3 '),
(' 363 oC',' 49 '),
(' 367 oC',' 112 '),
(' 378 oC',' 8 ')
Select
*
from #Test
This worked fine but doesn't account for the DQ issues which we are keeping in as this is what was recorded
TRY_CAST(REPLACE(Temperature, 'oC', '') AS DECIMAL(19,8))
I believe this will get you close.
SELECT *,
CASE
WHEN ISNUMERIC(REPLACE(REPLACE(REPLACE(Temperature, 'oC', ''), ' ', ''), '.', '')) = 1
THEN CONVERT(INT, (REPLACE(REPLACE(REPLACE(Temperature, 'oC', ''), ' ', ''), '.', '')))
ELSE NULL END AS TemperatureValue
FROM #Test
Hope this helps you out.
Related
How to count rows by date in mysql and show dynamic headers
I need to show count of each sources(type colum) and show according to date range Currently my data is as following id type date 11 air 2019-10-21 10:00:01 21 air 2019-10-21 10:00:02 31 air 2019-10-21 10:01:03 41 air 2019-10-21 11:01:03 51 air 2019-10-21 12:01:03 61 water 2019-10-21 12:01:03 71 water 2019-10-21 15:01:04 81 water 2019-10-22 16:01:03 81 sea 2019-10-22 16:01:03 81 sea 2019-10-24 16:01:03 I want to achive output like the following type 2019-10-21 | 2019-10-22 air 5 0 water 2 1 sea 0 1 and also give range in between 2019-10-21 and 2019-10-21 i have tried this query SELECT GROUP_CONCAT(DISTINCT CONCAT( 'count(case when type = ', 'type', ' then type else null end) AS ''', date(date), '''' ) ) INTO #sql FROM content where date(`date`) between '2021-02-08' AND '2021-02-10'; SET #sql = CONCAT('SELECT type, ', #sql, ' FROM content GROUP BY type limit 2'); PREPARE stmt FROM #sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; but it give wrong results and counts the total type 2021-02-08 2021-02-09 2021-02-10 sea 3 3 3 air 5316 5316 5316
MySQL Field Data Parsing
Started here, I was asked to create a new post in order to flesh it out which I'll try to do here but I'm afraid it's rather wordy. I created a test table with what seems to be a good cross-section of the data that needs to be parsed. Using this query from here to which I added some additional fields that are needed, this is the query now. SELECT ID, PartNo, GROUP_CONCAT( REPLACE(t.part, '-', CONCAT(' ', LEFT(t.part, 2))) ORDER BY t.ModelList SEPARATOR ' ' ) Models FROM ( SELECT t.ID, t.PartNo, t.Models, p.ModelList, REPLACE(REPLACE( SUBSTRING_INDEX(t.Models, ';', p.ModelList), SUBSTRING_INDEX(t.Models, ';', p.ModelList - 1), '' ), ';', '') part FROM parts_listing t CROSS JOIN ( SELECT 1 ModelList UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 ) p WHERE REPLACE(REPLACE(Models, '-', ''), ';', '') REGEXP '^[0-9]*$' ) t WHERE t.part <> '' GROUP BY t.ID, t.PartNo, t.Models ORDER BY t.PartNo, t.Models For the most basic parts, the Models data looks like this: 2206-13-26-33; 2302-06-13-32-33 . . . and this is the part that I am working on now. The Models column also contains ALL 23RD etc that will also need to be parsed somehow but for now I am concerned only with the data as shown above and I need to parse it to something like: 2206 2213 2226 2233 2302 2306 2313 2332 2333 The query above, however, seems to be repeating the first bit so it comes out as: 2206 2213 2226 2233 2202 2206 2213 2232 2233 It gives the result in one chunk but it would also be okay if each result was on it's own line as ultimately it will be dumped into another table and that is the way it will be by then. It also gives too few results. The actual table contains over 15,000 rows but this is fetching only a small fraction and in the data sample below, it should fetch about 20 rows but actually fetches only 6 although the fiddle, which has a very limited data set, does indeed give the proper results. Running the the fiddle query against my own data fetches only 555 rows. A cross-section sample of data can be created with this: DROP TABLE IF EXISTS `parts_listing`; CREATE TABLE IF NOT EXISTS `parts_listing` ( `ID` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `GroupNumber` varchar(20) DEFAULT NULL, `PartNo` varchar(30) DEFAULT NULL, `Models` varchar(255) DEFAULT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; INSERT INTO `parts_listing` (`ID`, `GroupNumber`, `PartNo`, `Models`) VALUES (1, '0.000', '391906', '2201-02-11-20-22-32-40; 2301'), (2, '0.000', '391907', '2206-26-33'), (3, '0.000', '399391', '2213'), (4, '0.000', '415209', '2302-06-32-33'), (5, '0.000', '415245', '2313'), (6, '0.000', '437273', 'ALL 24TH; 25TH; 26TH'), (7, '0.000', '436803', '2631 (BODY 2678); 5431 (BODY 5478)'), (8, '0.000', '448611', 'ALL 54TH'), (9, '0.0015', '372174', 'ALL 22ND; 23RD'), (10, '0.0015', '399324', '2201-02-11-20-22-32-40; 2301'), (11, '0.0015', '399324', '2206-13-26-33; 2302-06-13-32-33'), (12, '0.0015', '372146', 'ALL 22ND; 23RD'), (13, '0.0015', 'G179359', '2201-02-11-20-22-32-40; 2301'), (14, '0.0015', 'G179559', '2206-13-26-33; 2302-06-13-32-33'), (15, '0.0015', '422024', '2201-02-11-20-22-32-40; 2301'), (16, '0.0015', '422024', '2206-13-26-33; 2302-06-13-32-33'), (17, '0.0016', '378664', 'ALL 22ND; 23RD'), (18, '0.0016', 'G178532', 'ALL 22ND; 23RD'), (19, '0.0016', 'G123197', 'ALL 22ND; 23RD'), (20, '30.793', '448421', 'ALL 54TH'), (21, '30.7932', '422762', '2462-65-92-95-98; 2562-65-92-95; 2662-65-92-95'), (22, '30.7932', '448902', '5462-65-67-82-85-92-95-97'), (23, '30.7938', '399941', 'ALL 22ND; 23RD'), (24, '30.7938', '425809', 'ALL 24TH; 25TH; 26TH'), (25, '30.7938', '447799', 'ALL 54TH'), (26, '30.79383', '399927', 'ALL 22ND; 23RD; 24TH; 25TH; 26TH'), (27, '30.79396', 'PA437550', '2562-65-77-79; 2677-79'), (28, '30.79398', '422470', '2452-72; 2552-72'), (29, '30.79398', '422471', '2452-72; 2552-72'), (30, '30.79398', '422553', 'ALL 24TH; 25TH'), (31, '30.8007', '425517', '2413-52-62-65-67-72-92-95-98; 2552-62-65-72-77-92-95; 2650-51-52-62-65-72-77-92-95-97; 5450-51-52-62-65-67-72-77-82-85-92-95-97'), (32, '30.8007', '425920', 'RHD, 2462-65-92-95; 2562-65-92-95; 2662-65-92-95-97; 5462-65-82-85-92-95-97'), (33, '30.8044', 'G129662', '2293');
I think you need a more sophisticated way to verify that the Models column values are correct due to spaces after semicolons. In addition, if you need to process the Models column values that contain more than ten parts, you will need a longer sequence of numbers. I use the INFORMATION_SCHEMA COLUMNS table for this. You can also create an auxiliary table for this. SELECT CONCAT( IF(N.n = 0, '', LEFT(t.part, 2)), SUBSTRING_INDEX( SUBSTRING_INDEX(t.part, '-', N.n + 1), '-', -1 ) ) AS part, t.isHD, t.ID, t.GroupNumber, t.PartNo, t.Models FROM Numbers AS N CROSS JOIN ( SELECT SUBSTRING_INDEX( SUBSTRING_INDEX(t.part, ' ', N.n + 1), ' ', -1 ) AS part, t.isHD, t.ID, t.GroupNumber, t.PartNo, t.Models FROM Numbers AS N CROSS JOIN ( SELECT SUBSTRING_INDEX( SUBSTRING_INDEX(t.part, ';', N.n + 1), ';', -1 ) AS part, t.isHD, t.ID, t.GroupNumber, t.PartNo, t.Models FROM Numbers AS N CROSS JOIN ( SELECT REPLACE( SUBSTRING_INDEX( SUBSTRING_INDEX(t.part, 'LHD', N.n + 1), 'LHD', -1 ), ',', '' ) AS part, IF(N.n > 0, 1, t.isHD) AS isHD, t.ID, t.GroupNumber, t.PartNo, t.Models FROM Numbers AS N CROSS JOIN ( SELECT SUBSTRING_INDEX( SUBSTRING_INDEX(p.Models, 'RHD', N.n + 1), 'RHD', -1 ) AS part, IF(N.n > 0, 2, 0) AS isHD, p.ID, p.GroupNumber, p.PartNo, p.Models FROM Numbers AS N CROSS JOIN parts_listing AS p WHERE p.Models REGEXP '[[:<:]]([LR]HD,? +)?[0-9]+(-[0-9]+)*[[:>:]]' AND N.n <= (LENGTH(p.Models) - LENGTH(REPLACE(p.Models, 'RHD', ''))) / 3 ) AS t WHERE N.n <= (LENGTH(t.part) - LENGTH(REPLACE(t.part, 'LHD', ''))) / 3 ) AS t WHERE N.n <= LENGTH(t.part) - LENGTH(REPLACE(t.part, ';', '')) ) AS t WHERE N.n <= LENGTH(t.part) - LENGTH(REPLACE(t.part, ' ', '')) ) AS t WHERE t.part REGEXP '^[0-9]+(-[0-9]+)*$' AND N.n <= LENGTH(t.part) - LENGTH(REPLACE(t.part, '-', '')); Partial output (29 rows): +------+------+----+-------------+---------+--------------------------------------+ | part | isHD | ID | GroupNumber | PartNo | Models | +------+------+----+-------------+---------+--------------------------------------+ | 2201 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2202 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2211 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2220 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2222 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2232 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2240 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2301 | 0 | 1 | 0.000 | 391906 | 2201-02-11-20-22-32-40; 2301 | | 2213 | 1 | 3 | 0.000 | 399391 | LHD 2213 | | 2313 | 2 | 5 | 0.000 | 415245 | RHD, 2313 | | 2631 | 0 | 7 | 0.000 | 436803 | 2631 (BODY 2678); 5431 (BODY 5478) | | 5431 | 0 | 7 | 0.000 | 436803 | 2631 (BODY 2678); 5431 (BODY 5478) | | 2206 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2213 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2226 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2233 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2302 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2306 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2313 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2332 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2333 | 1 | 14 | 0.0015 | G179559 | LHD, 2206-13-26-33; 2302-06-13-32-33 | | 2201 | 0 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | | 2202 | 0 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | | 2211 | 0 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | | 2220 | 0 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | | 2222 | 0 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | | 2232 | 0 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | | 2240 | 0 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | | 2301 | 2 | 15 | 0.0015 | 422024 | 2201-02-11-20-22-32-40; RHD, 2301 | +------+------+----+-------------+---------+--------------------------------------+ Demo on DB Fiddle.
You can try this. I changed the parts where You split the Models column. I split them into different rows, and let the code from forpas go over it and join them again together. rows with text in it aren't touched, because you didn't specify nothing. select Id,GroupNumber,PartNo, group_concat( replace(t.part, '-', concat(' ', left(t.part, 2))) order by t.partno, t.part ASC separator ' ' ) Models from (SELECT Id,GroupNumber,PartNo, TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(models, ';', n.digit+1), ';', -1)) part FROM ( SElECT Id,GroupNumber,PartNo, REPLACE(REPLACE(REPLACE(Models, ')', ''), 'RHD,', ''), '(BODY', ';') Models FROM parts_listing ) p_l INNER JOIN (SELECT 0 digit UNION ALL select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) n ON LENGTH(REPLACE(Models, ';' , '')) <= LENGTH(Models)-n.digit Where REPLACE(REPLACE(REPLACE(Models, '-', ''), ' ', ''), ';', '') REGEXP '^[0-9]+$' ORDER BY Id, n.digit,part) t Group by Id,GroupNumber,PartNo ; Gets you Id GroupNumber PartNo Models 1 0.000 391906 2201 2202 2211 2220 2222 2232 2240 2301 2 0.000 391907 2206 2226 2233 3 0.000 399391 2213 4 0.000 415209 2302 2306 2332 2333 5 0.000 415245 2313 7 0.000 436803 2631 2678 5431 5478 10 0.0015 399324 2201 2202 2211 2220 2222 2232 2240 2301 11 0.0015 399324 2206 2213 2226 2233 2302 2306 2313 2332 2333 13 0.0015 G179359 2201 2202 2211 2220 2222 2232 2240 2301 14 0.0015 G179559 2206 2213 2226 2233 2302 2306 2313 2332 2333 15 0.0015 422024 2201 2202 2211 2220 2222 2232 2240 2301 16 0.0015 422024 2206 2213 2226 2233 2302 2306 2313 2332 2333 21 30.7932 422762 2462 2465 2492 2495 2498 2562 2565 2592 2595 2662 2665 2692 2695 22 30.7932 448902 5462 5465 5467 5482 5485 5492 5495 5497 27 30.79396 PA437550 2562 2565 2577 2579 2677 2679 28 30.79398 422470 2452 2472 2552 2572 29 30.79398 422471 2452 2472 2552 2572 31 30.8007 425517 2413 2452 2462 2465 2467 2472 2492 2495 2498 2552 2562 2565 2572 2577 2592 2595 2650 2651 2652 2662 2665 2672 2677 2692 2695 2697 5450 5451 5452 5462 5465 5467 5472 5477 5482 5485 5492 5495 5497 32 30.8007 425920 2462 2465 2492 2495 2562 2565 2592 2595 2662 2665 2692 2695 2697 5462 5465 5482 5485 5492 5495 5497 33 30.8044 G129662 2293 Dbfiddle example
MySQL pivot row to column dynamically
i have table:day id | jour 1 Lundi 01 Août 2016 2 Mardi 02 Août 2016 3 Mercredi 03 Août 2016 4 Jeudi 04 Août 2016 there will be 50 rows i want output like: Lundi 01 Août 2016 Mardi 02 Août 2016 Mercredi 03 Août 2016 1 2 3
you can do it easy with this queries: first generate the query and then execute it as prepared statement. SET SESSION group_concat_max_len = 1000000; SELECT CONCAT('SELECT ', GROUP_CONCAT( CONCAT ( "MAX(IF(`jour` = '",jour,'\',id,NULL)) AS `',jour,'`' ) ), ' FROM `day`' ) INTO #SQL FROM ( SELECT * FROM `day` ORDER BY id LIMIT 1,2 ) AS data; select #SQL; -- see the query only for debug PREPARE stmt FROM #SQL; EXECUTE stmt; DEALLOCATE PREPARE stmt; sample MariaDB [yourSchema]> select * from day; +----+------------------------+ | id | jour | +----+------------------------+ | 1 | Lundi 01 Août 2016 | | 2 | Mardi 02 Août 2016 | | 3 | Mercredi 03 Août 2016 | | 4 | Jeudi 04 Août 2016 | +----+------------------------+ 4 rows in set (0.00 sec) MariaDB [yourSchema]> SELECT -> CONCAT('SELECT ', -> GROUP_CONCAT( -> CONCAT ( -> "MAX(IF(`jour` = '",jour,'\',id,NULL)) AS `',jour,'`' -> ) -> ), -> ' FROM `day`' -> ) INTO #SQL -> FROM `day`; Query OK, 1 row affected (0.00 sec) MariaDB [yourSchema]> PREPARE stmt FROM #SQL; Query OK, 0 rows affected (0.00 sec) Statement prepared MariaDB [yourSchema]> EXECUTE stmt; +---------------------+---------------------+------------------------+---------------------+ | Lundi 01 Août 2016 | Mardi 02 Août 2016 | Mercredi 03 Août 2016 | Jeudi 04 Août 2016 | +---------------------+---------------------+------------------------+---------------------+ | 1 | 2 | 3 | 4 | +---------------------+---------------------+------------------------+---------------------+ 1 row in set (0.00 sec) MariaDB [yourSchema]> DEALLOCATE PREPARE stmt; Query OK, 0 rows affected (0.00 sec) MariaDB [yourSchema]>
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.
Omnet++ GUI keeps crashing
i guess the problem was the file ~/.tkenvrc after removing it everything was fine. Only problem was that its not deleted or reset with make clean. It seems that it saves the current arrangement and values of the GUI In case anybody else has this error i hope this post is of some help. cheers Initializing Global User Observer 2014-07-07 13:01:19.526 OverSim[1039:507] An uncaught exception was raised 2014-07-07 13:01:19.527 OverSim[1039:507] Error (1000) creating window shape 2014-07-07 13:01:19.527 OverSim[1039:507] ( 0 CoreFoundation 0x00007fff8717925c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff8e5b4e75 objc_exception_throw + 43 2 CoreFoundation 0x00007fff8717910c +[NSException raise:format:] + 204 3 AppKit 0x00007fff92d7c9d9 _NSCreateWindowWithOpaqueShape2 + 159 4 AppKit 0x00007fff92d7ba41 -[NSWindow _commonAwake] + 3720 5 AppKit 0x00007fff92d7a717 -[NSWindow _makeKeyRegardlessOfVisibility] + 85 6 AppKit 0x00007fff92d7a690 -[NSWindow makeKeyAndOrderFront:] + 29 7 Tk 0x000000010482dbeb XMapWindow + 134 8 Tk 0x00000001047a1afd Tk_MapWindow + 69 9 Tk 0x00000001047a9e6a TkInstallFrameMenu + 271 10 Tcl 0x000000010492b70d TclServiceIdle + 87 11 Tcl 0x0000000104912cee Tcl_DoOneEvent + 344 12 Tk 0x00000001047a9e57 TkInstallFrameMenu + 252 13 Tcl 0x000000010492b70d TclServiceIdle + 87 14 Tcl 0x0000000104912cee Tcl_DoOneEvent + 344 15 Tk 0x0000000104783760 TkGetDisplayOf + 972 16 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 17 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 18 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 19 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 20 Tcl 0x00000001048a9d9d Tcl_EvalEx + 1838 21 Tcl 0x00000001048ab030 Tcl_VarEvalVA + 147 22 Tcl 0x00000001048ab0fb Tcl_VarEval + 148 23 libopptkenvd.dylib 0x000000010392092a _ZN19TGraphicalModWindow12createWindowEv + 194 24 libopptkenvd.dylib 0x0000000103900bef _ZN5Tkenv7inspectEP7cObjectiPKcPv + 529 25 libopptkenvd.dylib 0x000000010392fe24 _ZN21cInspectByNameVisitor5visitEP7cObject + 392 26 liboppsimd.dylib 0x0000000103debb53 _ZN11cSimulation12forEachChildEP8cVisitor + 63 27 libopptkenvd.dylib 0x000000010392fe5c _ZN21cInspectByNameVisitor5visitEP7cObject + 448 28 liboppsimd.dylib 0x0000000103dfd07b _ZN8cVisitor7processEP7cObject + 47 29 libopptkenvd.dylib 0x000000010392ec5d _Z19inspectObjectByNamePKcS0_iS0_ + 85 30 libopptkenvd.dylib 0x0000000103914d14 _Z17inspectByName_cmdPvP10Tcl_InterpiPPKc + 264 31 Tcl 0x00000001048a7786 TclInvokeStringCommand + 124 32 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 33 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 34 Tcl 0x00000001048ecdbc Tcl_ExprObj + 38935 35 Tcl 0x00000001048aa73f TclEvalObjEx + 422 36 Tcl 0x00000001048b2fa4 TclDumpMemoryInfo + 19667 37 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 38 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 39 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 40 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 41 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 42 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 43 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 44 Tcl 0x00000001048a9d9d Tcl_EvalEx + 1838 45 Tcl 0x00000001048ab030 Tcl_VarEvalVA + 147 46 Tcl 0x00000001048ab0fb Tcl_VarEval + 148 47 libopptkenvd.dylib 0x0000000103900f16 _ZN5Tkenv16updateInspectorsEv + 426 48 libopptkenvd.dylib 0x0000000103900970 _ZN5Tkenv6newRunEPKci + 566 49 libopptkenvd.dylib 0x000000010390cebd _Z10newRun_cmdPvP10Tcl_InterpiPPKc + 126 50 Tcl 0x00000001048a7786 TclInvokeStringCommand + 124 51 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 52 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 53 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 54 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 55 Tcl 0x00000001048a9d9d Tcl_EvalEx + 1838 56 Tcl 0x00000001048aa54e Tcl_Eval + 39 57 libopptkenvd.dylib 0x00000001038fec16 _ZN5Tkenv3runEv + 1788 58 liboppenvird.dylib 0x0000000103a4c20e _ZN9EnvirBase3runEiPPcP14cConfiguration + 414 59 liboppenvird.dylib 0x0000000103a48ee2 _Z18setupUserInterfaceiPPc + 2570 60 liboppenvird.dylib 0x0000000103a49e51 evMain + 81 61 OverSim 0x0000000100832855 main + 32 62 libdyld.dylib 0x00007fff8a8435fd start + 1 ) 2014-07-07 13:01:19.528 OverSim[1039:507] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating window shape' *** First throw call stack: ( 0 CoreFoundation 0x00007fff8717925c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff8e5b4e75 objc_exception_throw + 43 2 CoreFoundation 0x00007fff8717910c +[NSException raise:format:] + 204 3 AppKit 0x00007fff92d7c9d9 _NSCreateWindowWithOpaqueShape2 + 159 4 AppKit 0x00007fff92d7ba41 -[NSWindow _commonAwake] + 3720 5 AppKit 0x00007fff92d7a717 -[NSWindow _makeKeyRegardlessOfVisibility] + 85 6 AppKit 0x00007fff92d7a690 -[NSWindow makeKeyAndOrderFront:] + 29 7 Tk 0x000000010482dbeb XMapWindow + 134 8 Tk 0x00000001047a1afd Tk_MapWindow + 69 9 Tk 0x00000001047a9e6a TkInstallFrameMenu + 271 10 Tcl 0x000000010492b70d TclServiceIdle + 87 11 Tcl 0x0000000104912cee Tcl_DoOneEvent + 344 12 Tk 0x00000001047a9e57 TkInstallFrameMenu + 252 13 Tcl 0x000000010492b70d TclServiceIdle + 87 14 Tcl 0x0000000104912cee Tcl_DoOneEvent + 344 15 Tk 0x0000000104783760 TkGetDisplayOf + 972 16 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 17 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 18 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 19 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 20 Tcl 0x00000001048a9d9d Tcl_EvalEx + 1838 21 Tcl 0x00000001048ab030 Tcl_VarEvalVA + 147 22 Tcl 0x00000001048ab0fb Tcl_VarEval + 148 23 libopptkenvd.dylib 0x000000010392092a _ZN19TGraphicalModWindow12createWindowEv + 194 24 libopptkenvd.dylib 0x0000000103900bef _ZN5Tkenv7inspectEP7cObjectiPKcPv + 529 25 libopptkenvd.dylib 0x000000010392fe24 _ZN21cInspectByNameVisitor5visitEP7cObject + 392 26 liboppsimd.dylib 0x0000000103debb53 _ZN11cSimulation12forEachChildEP8cVisitor + 63 27 libopptkenvd.dylib 0x000000010392fe5c _ZN21cInspectByNameVisitor5visitEP7cObject + 448 28 liboppsimd.dylib 0x0000000103dfd07b _ZN8cVisitor7processEP7cObject + 47 29 libopptkenvd.dylib 0x000000010392ec5d _Z19inspectObjectByNamePKcS0_iS0_ + 85 30 libopptkenvd.dylib 0x0000000103914d14 _Z17inspectByName_cmdPvP10Tcl_InterpiPPKc + 264 31 Tcl 0x00000001048a7786 TclInvokeStringCommand + 124 32 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 33 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 34 Tcl 0x00000001048ecdbc Tcl_ExprObj + 38935 35 Tcl 0x00000001048aa73f TclEvalObjEx + 422 36 Tcl 0x00000001048b2fa4 TclDumpMemoryInfo + 19667 37 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 38 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 39 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 40 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 41 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 42 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 43 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 44 Tcl 0x00000001048a9d9d Tcl_EvalEx + 1838 45 Tcl 0x00000001048ab030 Tcl_VarEvalVA + 147 46 Tcl 0x00000001048ab0fb Tcl_VarEval + 148 47 libopptkenvd.dylib 0x0000000103900f16 _ZN5Tkenv16updateInspectorsEv + 426 48 libopptkenvd.dylib 0x0000000103900970 _ZN5Tkenv6newRunEPKci + 566 49 libopptkenvd.dylib 0x000000010390cebd _Z10newRun_cmdPvP10Tcl_InterpiPPKc + 126 50 Tcl 0x00000001048a7786 TclInvokeStringCommand + 124 51 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 52 Tcl 0x00000001048e8d6a Tcl_ExprObj + 22469 53 Tcl 0x000000010491fdea TclObjInterpProcCore + 699 54 Tcl 0x00000001048a8ab6 Tcl_ListMathFuncs + 1503 55 Tcl 0x00000001048a9d9d Tcl_EvalEx + 1838 56 Tcl 0x00000001048aa54e Tcl_Eval + 39 57 libopptkenvd.dylib 0x00000001038fec16 _ZN5Tkenv3runEv + 1788 58 liboppenvird.dylib 0x0000000103a4c20e _ZN9EnvirBase3runEiPPcP14cConfiguration + 414 59 liboppenvird.dylib 0x0000000103a48ee2 _Z18setupUserInterfaceiPPc + 2570 60 liboppenvird.dylib 0x0000000103a49e51 evMain + 81 61 OverSim 0x0000000100832855 main + 32 62 libdyld.dylib 0x00007fff8a8435fd start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6