AOB
Registered User.
- Local time
- Today, 23:52
- Joined
- Sep 26, 2012
- Messages
- 620
I have a query which takes a parameter (a User ID) and then appends a record to a table using that parameter, along with a couple of other fields from a staging table, assuming a similar record doesn't already exist (tested using an outer join). Not a complicated query and I have dozens of similar elsewhere.
What's puzzling me is, this query fails with the following message :
A quick bit of debugging narrowed it down to this field/value :
Which I thought was kinda strange as the parameter is already defined as being a Long Integer (from the first line of the query) and the receiving field is similarly defined as containing Long Integers (?)
Sure enough, if I explicitly "re-cast" the parameter as a Long Integer in the INSERT clause, the query works :
Why would this be necessary / what am I overlooking in either the query or the destination table that might cause the engine to need to coerce the variable into a data type that has already been defined correctly?
What's concerning me is, I have loads of these kinds of queries, and this is the only one that doesn't seem to "trust" the data type being passed (even though I've confirmed everything looks exactly as it should / as I would expect?)
Thanks
Al
SQL:
PARAMETERS SpecifiedUserID Long;
INSERT INTO tblEmployees
SELECT sE.EmployeeID AS EmployeeID, SpecifiedUserID AS CreatedBy, Now AS CreatedTimeLocal, ConvertLocalTimetoUTCTime(Now) AS CreatedTimeUTC
FROM stgEmployees AS sE
LEFT JOIN tblEmployees AS E ON sE.EmployeeID = E.EmployeeID
WHERE E.EmployeeID IS NULL;
What's puzzling me is, this query fails with the following message :
Number of query values and destination fields are not the same
A quick bit of debugging narrowed it down to this field/value :
SpecifiedUserID AS CreatedBy
Which I thought was kinda strange as the parameter is already defined as being a Long Integer (from the first line of the query) and the receiving field is similarly defined as containing Long Integers (?)
Sure enough, if I explicitly "re-cast" the parameter as a Long Integer in the INSERT clause, the query works :
SQL:
PARAMETERS SpecifiedUserID Long;
INSERT INTO tblEmployees
SELECT sE.EmployeeID AS EmployeeID, CLng(SpecifiedUserID) AS CreatedBy, Now AS CreatedTimeLocal, ConvertLocalTimetoUTCTime(Now) AS CreatedTimeUTC
FROM stgEmployees AS sE
LEFT JOIN tblEmployees AS E ON sE.EmployeeID = E.EmployeeID
WHERE E.EmployeeID IS NULL;
Why would this be necessary / what am I overlooking in either the query or the destination table that might cause the engine to need to coerce the variable into a data type that has already been defined correctly?
What's concerning me is, I have loads of these kinds of queries, and this is the only one that doesn't seem to "trust" the data type being passed (even though I've confirmed everything looks exactly as it should / as I would expect?)
Thanks
Al