SQL Server Merge a javascript list with a table

Brass Contributor

I have a javascript object containing a bunch of user info that's sourced from Microsoft Teams team member list. I want to merge this object to a SQL table at predefined intervals. The team members of a team may be added/removed via Teams UI by users. However, my requirement is to keep the user table in SQL in sync will the actual team member list in Teams. I need a way to merge this list into the SQL table such that any existing users in the object kept intact in the db, any additional users are added and any unlisted users are removed from the db. I believe SQL merge operation could achieve this but that one works only if both the source and destination are tables.

 

Any idea how to achieve this when the source is a javascript object and destination is a table?

1 Reply

Hi @eynarain --

 

The easiest approach might be to break this task down into two distinct parts.  First, load the JSON data to a staging or temporary table in the database.  Next, perform your insert/merge into the primary base table.  

SQL Server has good JSON support.

https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-...