Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My query is rounding decimal values to integer. I understand the syntax of decimal(integers,decimals) itself however I do not understand how I implement this in my query. I do not see an answer which specifically addresses this so, if there is one, please simply point me to it.

I am running the following query within a VBA macro within Excel so I would think I am using MS SQL, please correct me if I am in error.

SELECT * from DateSlicedCDR.csv AS Q LEFT OUTER JOIN AreaCodes.csv AS R ON Q.[AreaPrefix] = R.[AreaPrefix] ORDER BY [BeginTimeDate] ASC

I realize csv files are by no means the ideal however I want to leave that aside for the moment and get the query straightened out then later perhaps change the data format to something better and faster.

What is happening is that one of the fields, which has a variable number of decimal places (max 7 decimals), is getting rounded so that when I write out the table created from my join, I no longer have the correct values.

If I have to explicitly state the fields instead of *, that is fine.

If I have done anything wrong in the posting of this question, or if you need additional information, please let me know as I am relatively new to the site.

Thank you.

What I have tried:

I looked at the field in the record set produced by my query and could see that the values had been rounded to the nearest integer. I searched the web and found that it appears I need to implement the decimal statement, but I can't find an example of how to do it.
Posted
Updated 31-May-16 13:36pm
Comments
CHill60 31-May-16 11:33am    
I can't see why any field would be rounded with this. If you are using a CSV file then you most definitely not querying MSSQL. Do you have a sample of the data in the file?
Maciej Los 31-May-16 11:39am    
What is input data and expected output?

1 solution

I would suggest the problem is to do with the Text Driver. When a CSV file is read using the Text Driver it determines the data-type for each column based on the first 'x' number of rows it reads, then the remaining data for that column is presumed to be the same.
Your issue is possibly occurring because the first 'x' rows are actually integer data.

The best solution is to create a Schema.ini file as it will tell the driver what the exact column type is.
Refer to following link;
MSDN - Schema.ini File (Text File Driver)
[^]
Place the Schema file in the same directory as the CSV file & you will get an Uncle named Bob.
EDIT: One Schema.ini can be used for multiple files

Kind Regards
 
Share this answer
 
v2
Comments
Member 12405198 3-Jun-16 15:06pm    
BEAUTIFUL!!!! Thank you SO MUCH!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900