Integration using database view

shashuma
Kilo Contributor

Hi all,

I'm currently doing integration between ServiceNow and MS SQL database. Trying to retrieve SN data and update the SQL db.

The data in SN will be coming from multiple tables. I've used the database view to join all the tables together and return the API of the database view.

Database view in ServiceNow doesn't provide much filtering, so I've run into the following issue.

I need to join 5 tables, but to simplify the question, that's say I'm only joining 2 tables.

TableA                                      

cost type(reference field)table typejob number
Farmcost_breakdownJOB01
Agencycost_breakdownJOB01
Servicecost_breakdownJOB02
Directcost_breakdownJOB03

TableB

table type
cost type(string)rank
cost_breakdownFarm2000
cost_breakdownOthers3000

I need to return the following columns, job number and rank

Job numberrank
JOB012000
JOB013000
JOB023000
JOB033000

Join the two tables, if the cost type = 'Farm', rank will be 2000, otherwise, rank will be 3000.

As the cost type in TableA is a reference field, the join i had didn't work.

My where clause: tableA_table_type=tableB_table_type&&tableA_cost_type=tableB_cost_type

What have I done wrong here?

As explained in the beginning, all I'm trying to achieve is to pass data from multiple tables in SN to a single MS SQL db table. What other options do I have? I don't want to go with Linked Server approach.

Thanks in advance,

June

1 REPLY 1

Chris M3
Tera Guru

Yeah, the issue would be in your reference join to your string field.



I don't think you can dot-walk in the where clause, but you could try that.



More likely, you need to add the referenced table to your database view



so something like


table_a_cost_type = ref_table_sys_id



Then


table_b_cost_type = ref_table_display_field