How can we explicitly convert data types in INSERT INTO/SELECT queries in MS Access?
Sample Query:
INSERT INTO pStudents( pStudentID, pDate, pRate, pGrade )
SELECT sStudentID, sDate, sRate, sGrade
FROM sStudents
WHERE (((sStudents.sStudentID) Is Not Null);
Here I want to convert fields from sStudents table before inserting in pStudents to following:
pStudentID = text
pDate = Short Date
pRate = Double
pGrade = text
Thanks in advance
You can use the built-in conversion functions of Access in the queries:
…or as an
INSERTquery:Did you mean something like that?
EDIT:
Okay, your sample query with conversions would look like this:
However, this will only work if the columns contain only data that can actually be converted into the given type.
For example, you can convert a
Stringcolumn toDoublewithCDbl()– but only if the selected rows contain only values that can actually be converted intoDouble.As soon as you select one row with a value that contains something else than numeric values (like ‘hello’), the conversion will fail.
On the other hand, do you really need the conversions?
Access can convert a lot by itself. For example, you can insert values from a numeric column into a string column, Access will convert it by itself. You don’t have to use
CStr()for that.