AmishJohn81 AmishJohn81 - 5 months ago 18
Node.js Question

How to avoid SQL RequestError: "The multi-part identifier ... could not be bound"?

I am getting a SQL RequestError while trying to insert a string into a SQL Server table. The string is

. I think that the periods in the string are throwing some kind of red flag that it is a reference to some property of an object, or something along those lines. I am using the mssql node module for the request.

let myObj = {
Date: '2015-06-22',
PackageName: 'com.softek.ofxclmobile.patriotfcu'

let date = myObj['Date']
let pName = myObj['PackageName']

request.query('insert into myTable ([DATE],[PackageName]) values (' + date + ',' + pName + '))

I have not found anything online about trying to avoid using the dot notation, but I have found some of the opposite, trying to get into the notation. I also looked but there is no RegExp keyword to keep a period as literally a period.

The exact Error:

{ [RequestError: The multi-part identifier "com.softek.ofxclmobile.patriotfcu" could not be bound.]
name: 'RequestError',
message: 'The multi-part identifier "com.softek.ofxclmobile.patriotfcu" could not be bound.',
code: 'EREQUEST',
number: 4104,
lineNumber: 1,
state: 1,
class: 16,
serverName: 'PFCUAPPDEV01',
procName: '' }


can you use double quotes to wrap the sql

request.query("insert into myTable ([DATE],[PackageName]) values ('" + date + "','" + pName + "')")

Just to be safe, you may want replace any single quotes in pName with TWO single quotes