Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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
Sql server Msg 102,15级,状态1,第3行“+”附近语法不正确。5._Sql Server_Database - Fatal编程技术网

Sql server Msg 102,15级,状态1,第3行“+”附近语法不正确。5.

Sql server Msg 102,15级,状态1,第3行“+”附近语法不正确。5.,sql-server,database,Sql Server,Database,如果您的代码应该是SQL Server查询,则不需要引号。相反,您可以使用如下所示的单个查询: select SUM(dr_amount)-SUM(cr_amount)" + "from Gl_Transaction where Accountno like'1%' select SUM(dr_amount)-SUM(cr_amount)" + "from Gl_Transaction where Accountno like'2%'" + "select SUM(dr_amount)-SUM(

如果您的代码应该是SQL Server查询,则不需要引号。相反,您可以使用如下所示的单个查询:

select SUM(dr_amount)-SUM(cr_amount)" +
"from Gl_Transaction where Accountno like'1%' select SUM(dr_amount)-SUM(cr_amount)" +
"from Gl_Transaction where Accountno like'2%'" +
"select SUM(dr_amount)-SUM(cr_amount)" +
"from Gl_Transaction where Accountno like'3%'" +
"select SUM(dr_amount)-SUM(cr_amount)" +
"from Gl_Transaction where Accountno like'4%'" +
"select SUM(dr_amount)-SUM(cr_amount)" +
"from Gl_Transaction where Accountno like'5%'";
编辑: 看起来您实际上只是想要一个查询,该查询将返回帐号以001、002或003开头的数据

下面是两个简单的查询,它们将满足您的需要:

SELECT SUM(dr_amount)-SUM(cr_amount)
FROM Gl_Transaction
WHERE CONVERT(varchar(max),Accountno) LIKE'1%'

SELECT SUM(dr_amount)-SUM(cr_amount)
FROM Gl_Transaction
WHERE CONVERT(varchar(max),Accountno) LIKE'2%'

SELECT SUM(dr_amount)-SUM(cr_amount)
FROM Gl_Transaction
WHERE CONVERT(varchar(max),Accountno) LIKE'3%'

SELECT SUM(dr_amount)-SUM(cr_amount)
FROM Gl_Transaction
WHERE CONVERT(varchar(max),Accountno) LIKE'4%'

SELECT SUM(dr_amount)-SUM(cr_amount)
FROM Gl_Transaction
WHERE CONVERT(varchar(max),Accountno) LIKE'5%'
感谢@JiggsJedi提出了这个替代方案,我觉得比下面我最初的建议要好

SQL不使用…+连接行。。。移除它们

如果AccountNo是整数,则必须转换为字符串才能使用LIKE

SELECT SUM(dr_amount)-SUM(cr_amount)
FROM Gl_Transaction
WHERE CONVERT(varchar(max),Accountno) LIKE'001%'
OR CONVERT(varchar(max),Accountno) LIKE'002%'
OR CONVERT(varchar(max),Accountno) LIKE'003%'

“1%”和“选择”之间是否应该有“+”?我在“1%”和“选择”之间添加“+”时出现了相同的错误请清除缺少的引号并查看是否仍然存在错误。重新发布最新更新的代码和错误消息您试图完成什么?你不能像那样链接查询。我想在account num以001ok开头的地方获取数据。但是如果我想在account num以001开头的地方获取值,那么我可以进行哪个查询?什么值?如果您想查看所有内容,只需从Gl_事务中选择*,其中convertvarcharmax,Accountno类似于“1%”,但当我这样查询时,答案为空。可能我误解了您的意思,如果您想要AccountNum 001,您可以从Gl_事务中选择*,其中convertvarcharmax,Accountno如“001%”我在mu表事务中有不同的帐户。。。但是我只想要account num从001开始的记录,如果我想要account num以001002和003开始,我如何关联它们?您想要一个将返回account num以001或002或003开始的数据的查询吗?或2个查询,其中第一个将返回account num以001开头的数据,第二个将返回account num以002开头的数据,依此类推?1个查询将给出000002003条记录
SELECT SUM(dr_amount)-SUM(cr_amount)
FROM Gl_Transaction
WHERE CONVERT(varchar(max),Accountno) LIKE'001%'
OR CONVERT(varchar(max),Accountno) LIKE'002%'
OR CONVERT(varchar(max),Accountno) LIKE'003%'
select SUM(dr_amount)-SUM(cr_amount)
from Gl_Transaction where convert(varchar(max),Accountno) like'1%' 

select SUM(dr_amount)-SUM(cr_amount)
from Gl_Transaction where convert(varchar(max),Accountno) like'2%'

select SUM(dr_amount)-SUM(cr_amount)
from Gl_Transaction where convert(varchar(max),Accountno) like'3%'

select SUM(dr_amount)-SUM(cr_amount)
from Gl_Transaction where convert(varchar(max),Accountno) like'4%'

select SUM(dr_amount)-SUM(cr_amount)
from Gl_Transaction where convert(varchar(max),Accountno) like'5%'