Solved SQL copies data with indent (1 Viewer)

murray83

Games Collector
Local time
Today, 22:21
Joined
Mar 31, 2017
Messages
837
Hi All

have exhasusted AI and google help so thought would actually ask some proper smart people ( me not included )

so i have the following SQL

SQL:
INSERT INTO tblForCSV_main ( OrderNo, ProductCode, Qty )
SELECT Mid([RawData], InStr([RawData], "Booking Ref:") + 12, 12) AS BookingRef, Mid([RawData], InStr([RawData], "Pallets") + 21, 13) AS HSProductCode, Mid([RawData], InStr([RawData], "Pallets") + 68, 5) AS Qty
FROM TempRawData
WHERE TempRawData.RawData IS NOT NULL;

which for the most copies it fine apart from the OrderNo as it shows up like this in the tbl

1750253167036.png


am at a loss to why, but hope someone here will hold the key/secret
 
Most likely this is because that's what's in the data. Pretty confident it has nothing to do with your SQL.

This probably gets fixed by putting a Trim() around each field of the SELECT.
 
Hi All

have exhasusted AI and google help so thought would actually ask some proper smart people ( me not included )

so i have the following SQL

SQL:
INSERT INTO tblForCSV_main ( OrderNo, ProductCode, Qty )
SELECT Mid([RawData], InStr([RawData], "Booking Ref:") + 12, 12) AS BookingRef, Mid([RawData], InStr([RawData], "Pallets") + 21, 13) AS HSProductCode, Mid([RawData], InStr([RawData], "Pallets") + 68, 5) AS Qty
FROM TempRawData
WHERE TempRawData.RawData IS NOT NULL;

which for the most copies it fine apart from the OrderNo as it shows up like this in the tbl

View attachment 120251

am at a loss to why, but hope someone here will hold the key/secret
Where is that "TempRawData" coming from? That would appear to be the source of the problem. It looks like a hidden line break character in that source text. I don't think it would be an indent, or tab character.

You can probably resolve the immediate problem by "sanitizing" the input from that TempRawData source.

For example, you could try using replace to remove the unwanted line break character. But a thorough solution might need to account for other such non-printing characters.
 
Cheers all. Not back in work till Friday so will give it all a look then

But cheers
 
ok have tried loading the page at work ( and looks like blocked booo )

have attached database and one pdf which is the raw data

so steps open the PDF copy all ( ctrl + a ) and then paste into subform on the frm_Import just using ctl + v ( no paste special required )

then click Import and you will see that the order number is indented
 

Attachments

You are picking up the CRLF of the previous line?
1750407594153.png


Might even be a tab in there?
Edit: No tab, that is my length display. :(
1750408038912.png
 
Last edited:
No, trim removes spaces. In fact is is char(32) not CRLF.
Probably the easiest is to just run though the table afterwards and replace CHR(32) with nothing.
I would probably do it for all fields, as tomorrow, it could be another field.

1750408683728.png
 
Or correct your calcs in the query? However if this has been working fine before, then tidying it up after would be safer?
This is just the select
1750409153993.png
 
how about tidying with

SQL:
INSERT INTO tblForCSV_main (OrderNo, ProductCode, Qty)
SELECT
    Replace(Mid([RawData], InStr([RawData], "Booking Ref:") + 12, 12), ' ', '') AS BookingRef,
    Mid([RawData], InStr([RawData], "Pallets") + 21, 13) AS HSProductCode,
    Mid([RawData], InStr([RawData], "Pallets") + 68, 5) AS Qty
FROM
    TempRawData
WHERE
    TempRawData.RawData IS NOT NULL;
so does the insert and then cleans but again still seems to have that tab or what ever you said it was
 
You would need to specify what character you are replacing. It is hidden after all. :)
Code:
INSERT INTO tblForCSV_main (OrderNo, ProductCode, Qty)
SELECT
    Replace(Mid([RawData], InStr([RawData], "Booking Ref:") + 12, 12), CHR(32), '') AS BookingRef,
    Mid([RawData], InStr([RawData], "Pallets") + 21, 13) AS HSProductCode,
    Mid([RawData], InStr([RawData], "Pallets") + 68, 5) AS Qty
FROM
    TempRawData
WHERE
    TempRawData.RawData IS NOT NULL;

However, what if it happens with the others? Might be safer to replace on those as well?
 
Take the CRLF into account? That Chr(32) is elusive. :(

Code:
SELECT Replace(Mid([RawData],InStr([RawData],"Booking Ref:")+14,10),Chr(32),'') AS BookingRef, Asc(Mid([RawData],InStr([RawData],"Booking Ref:")+14,1)) AS Expr1, Mid([RawData],InStr([RawData],"Pallets")+21,13) AS HSProductCode, Mid([RawData],InStr([RawData],"Pallets")+68,5) AS Qty
FROM TempRawData
WHERE (((TempRawData.RawData) Is Not Null));
 
thanks for the reply which yes i didforget to say what to replace, but have some news

1750412382616.png


still has the gap should i not also put 13 for the CRLF ?
 
See my last post.
Why not work out where the actual text starts?
This works?
Code:
SELECT Mid([RawData],InStr([RawData],"Booking Ref:")+14,10) AS BookingRef, Asc(Mid([RawData],InStr([RawData],"Booking Ref:")+14,1)) AS Expr1, Mid([RawData],InStr([RawData],"Pallets")+21,13) AS HSProductCode, Mid([RawData],InStr([RawData],"Pallets")+68,5) AS Qty
FROM TempRawData
WHERE (((TempRawData.RawData) Is Not Null));
 
nobody appears to be mentioning chr(11) which is a horizontal tab before the space (chr(32)- that also needs to be removed

Are you really using copy/paste to populate your table?
 
nobody appears to be mentioning chr(11) which is a horizontal tab before the space (chr(32)- that also needs to be removed

Are you really using copy/paste to populate your table?
@CJ_London the 11 is the display of the length of the data
 
nobody appears to be mentioning chr(11) which is a horizontal tab before the space (chr(32)- that also needs to be removed

Are you really using copy/paste to populate your table?
yes as the data comes in a pdf and easiest way to get it in is copy and paste and then pick whats needed

and @Gasman sorry, yes you are correct it does work.

Many thanks all, closed ( for know )

:)
 
yes as the data comes in a pdf and easiest way to get it in is copy and paste and then pick whats needed

and @Gasman sorry, yes you are correct it does work.

Many thanks all, closed ( for know )

:)
Well check it for a few runs, but it seems to pick up that Chr(32) as well as the CRLF. :unsure:
However I think it was the CRLF causing your issue, the CHR(32) was found by accident. :)
 

Users who are viewing this thread

Back
Top Bottom