node-mssql icon indicating copy to clipboard operation
node-mssql copied to clipboard

sql.Bit always true

Open guruward opened this issue 10 years ago • 3 comments

trying to update a BIT value,

request.input('active', sql.Bit, req.body.Active); .... .... SET += ', Active = @active';

getting no errors but active is always true

guruward avatar Oct 20 '16 22:10 guruward

Might be helpful to provide more information about your use case. Example: What does your query statement look like? Is it a stored proc? If so, is @active a parameter exposed on it, or, is @active declared internally within the proc? What does your request.body look like?

StackBlaster avatar Oct 30 '16 17:10 StackBlaster

running as a parametrized query. client side problem passing a true false value. got it working

guruward avatar Oct 30 '16 21:10 guruward

Ran into the same problem, had to do following to make it work

    if (Enabled == 1 || Enabled.toUpperCase()  == "TRUE" || Enabled.toUpperCase()  == "YES"  || Enabled.toUpperCase()  == "Y")
    {
        Enabled = true;
    }
    else
    {
        Enabled = false;
    }

for a column defined as Bit mssql_request.input('Enabled', mssql.Bit, Enabled);

so this actually enables consumer to pass any of the values mentioned in if clause offering additional flexibility while solving the issue with Bit type

orshee avatar Feb 23 '18 16:02 orshee