Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQL SERVER选择子字符串_Php_Sql_Sql Server - Fatal编程技术网

Php SQL SERVER选择子字符串

Php SQL SERVER选择子字符串,php,sql,sql-server,Php,Sql,Sql Server,我有一张这样的桌子 +------------+----------+ | NPA | nama | +------------+----------+ | 0101010003 | adi | | 0101020004 | adu | | 0101030005 | ade | | 0102010006 | abi | | 0103010007 | 25910015 | +------------+----------+ 我有这样的

我有一张这样的桌子

+------------+----------+
|    NPA     |   nama   |
+------------+----------+
| 0101010003 | adi      |
| 0101020004 | adu      |
| 0101030005 | ade      |
| 0102010006 | abi      |
| 0103010007 | 25910015 |
+------------+----------+
我有这样的变量:
$npa1=01
$npa2=02
$npa3=03

如何进行SQL server 2014查询以获取第一个字符为
010101xxxx
010102xxxx
010103xxxx
如何在SQL server 2014和PHP中做到这一点?

我想您需要:

select t.*
from t
where left(npa, 6) in ('0101' + $npa1, '0101' + $npa2, '0101' + $npa3);
也就是说,您应该使用参数将值传递到查询中,而不是使用字符串