简体   繁体   中英

Having issues with SELECT in MSSQL

AM working on a project in CodeIgniter and am trying to change my project database from mysql to mssql, but unfortunately all my sql code that were working quite well in mysql are starting to generate errors i don't understand. The following method is used to verify if a user with the given TIN exists:

public function verify_user_tin( $user_tin )
{

    $this->usid = $user_tin;

    $this->db->select('taxpayer_id ')
        ->from('crirs_tin')
        ->where('tin', $this->usid)
        ->limit(1);

    $query = $this->db->get();

    return ( $query->num_rows() == 1 ? true : false );

}

I get the following error:

Error Number: HY000/208
Error Number: HY000/208

General SQL Server error: Check messages from the SQL Server [208] (severity 16) [SELECT TOP 1 "taxpayer_id" FROM "crirs_tin" WHERE "tin" = '1903798293-0001' ]

SELECT TOP 1 "taxpayer_id" FROM "crirs_tin" WHERE "tin" = '1903798293-0001'

Filename: models/Account_m.php
Line Number: 45

Why is a simple SELECT seemingly difficult in mssql? And please how do i fix this?

Try removing the double quotes around your table name like

SELECT TOP 1 "taxpayer_id" FROM crirs_tin WHERE "tin" = '1903798293-0001'

(OR) though it works better use SQL Server specific syntax

SELECT TOP 1 [taxpayer_id] FROM crirs_tin WHERE [tin] = '1903798293-0001'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM