Can anyone help/show me how to insert data into a table I have already created? Normally I would just JOIN these two together but the are on 2 different SQL servers so I cannot(unless I can?)
Here is the Named Query I have made for the existing table:
SELECT
VP.PERSONNUM AS 'BadgeNum'
, FORMAT( VP.INPUNCHDTM, 'hh:mm') AS 'ClockINTime'
, VP.PERSONFULLNAME AS 'Name'
, HOMELABORLEVELNM5 AS 'Shift'
, HOMELABORLEVELNM6 AS 'Dept'
, HOMELABORLEVELDSC7 AS 'JobTitle'
, HOMELABORLEVELDSC4 AS 'Supervisor'
FROM
VP_EMPCUREARNTIME AS VP
LEFT OUTER JOIN VP_EMPLOYEEV42 ON VP.PERSONNUM = VP_EMPLOYEEV42.PERSONNUM
LEFT OUTER JOIN TIMEZONE ON VP_EMPLOYEEV42.TIMEZONENAME = TIMEZONE.ENGLISH
WHERE
(VP.LABORLEVELNAME3 = '0065')
AND VP.INPUNCHDTM is not Null
AND VP.LABORLEVELNAME5 NOT IN ('9', 'S')
AND (VP.STARTDTM > DATEADD(d, - 1, GETDATE()))
AND (VP.GMTSTARTDTM <= DATEADD(S, - TIMEZONE.GMTOFFSET, GETDATE()))
AND (VP.GMTENDDTM IS NULL OR VP.GMTENDDTM >= DATEADD(S, - TIMEZONE.GMTOFFSET, GETDATE()))
order by HOMELABORLEVELNM6, HOMELABORLEVELDSC7
I am thinking that I would add the data from the table that I want to add into the transform script. Here is the transform script I have in place already on that Named Query:
def transform(self, value, quality, timestamp):
table = self.getSibling("Table_0").props.data
accounted_badge_num = [B['Badge_Num'] for B in table]
json_obj = []
for V in value:
py_dic = {"value":dict(V)}
if py_dic["value"]['BadgeNum'] in accounted_badge_num:
py_dic["value"]['isAccountedFor'] = True
py_dic["style"]={"backgroundColor":"green"}
else:
py_dic["value"]['isAccountedFor'] = False
json_obj.append(py_dic)
return json_obj
Here is a couple rows from the new table I want to add to this table:
Perhaps, I misunderstood. Are you wanting to combine two datasets with different columns but a matching primary key, or are you wanting to add rows from one dataset to another dataset with identical columns?
It was missing a column, fixed that, but still same error. Do the columns need to be in the same order?
Like table cloumn 1,2,3,4,5 - named query to run column1,2,4,3,5?
I honestly don't know if the order is important or not. I'm assuming that line 4 is the runNamedQuery(). Make sure that the named query is configured to return a dataset, also be sure that you are providing the correct path and a set of parameters if any (an empty dictionary if their are no parameters). I just threw that together, I don't know anything about how you have authored the Named Query.
I have the script worked out to where I have joined the 2 tables:
styleAccountedFor = {'backgroundColor': "green"}
MusterCall = system.db.runNamedQuery('MusterCall')
SM_Salary = system.db.runNamedQuery('SM_Salary')
combinedDataset = system.dataset.appendDataset(MusterCall,SM_Salary)
combinedData = system.dataset.toPyDataSet(combinedDataset)
headers = system.dataset.getColumnHeaders(combinedData)
checkedInData = (self.getSibling("Table_0").props.data)
accountedBadgeNum = [B['Badge_Num'] for B in checkedInData]
pyObj = []
for row in combinedData:
pyDict = {}
pyValueDict = {headers[i]: row[i] for i in range(len(row))}
if pyValueDict['BadgeNum'] in accountedBadgeNum:
pyValueDict['isAccountedFor'] = True
pyDict["style"] = styleAccountedFor
else:
pyValueDict['isAccountedFor'] = False
pyDict['value'] = pyValueDict
pyObj.append(pyDict)
return pyObj
I have an issue now that when I select the a row and press a button to make that row turn green, it removes the row from the table. The row should stay and turn green.