简体   繁体   English

MSSQL中的SELECT有问题

[英]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. 我在CodeIgniter中的一个项目上工作,正在尝试将我的项目数据库从mysql更改为mssql,但是不幸的是,我在mysql中运行良好的所有sql代码都开始产生我不理解的错误。 The following method is used to verify if a user with the given TIN exists: 以下方法用于验证具有给定TIN的用户是否存在:

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? 为什么简单的SELECT在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 (OR)尽管使用SQL Server特定语法效果更好

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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