This query works in Access:
Code:
SELECT a.siteid, a.value, a.timestamp, a.ParamID INTO Table1
FROM DeviceTypeData AS a
WHERE (((a.siteid)="105471") AND ((a.ParamID) In (Select Top 3 ParamID from [DeviceTypeData] where [siteid]=a.[siteid] Order By [ParamID] desc)));
I think I'm having trouble getting the quotes around the the site id. This is what I have that is NOT working, but is close since it worked without the site id filter added. SQL basically shows up like a.siteid=105471 instead of a.siteid="105471". I don't know, but this may be the problem with the following, but I'm not sure how to code that.
Code:
SQL = "SELECT a.siteid, a.value, a.timestamp, a.ParamID INTO " & CookedTable & _
" FROM " & SourceTable & " AS a" & _
" WHERE (((a.siteid=" & EquipID & ") AND ((a.ParamID) In (Select Top " & Value & " ParamID FROM " & "[" & SourceTable & "]" & _
" WHERE [siteid]=a.[siteid] Order By [ParamID] desc)));"
DoCmd.RunSQL SQL
So basically I get this, notice there is no " " around the 105471 and I get not table created. Any help?
Code:
SELECT a.siteid, a.value, a.timestamp, a.ParamID INTO Table1 FROM DeviceTypeData AS a WHERE (((a.siteid)=105471) AND ((a.ParamID) In (Select Top 3 ParamID from [DeviceTypeData] where [siteid]=a.[siteid] Order By [ParamID] desc)));