Syndax错误SQL查询执行 [英] Syndax error SQL query execution

查看:92
本文介绍了Syndax错误SQL查询执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个SQL查询,



  SELECT(月(bill_date)&','& year(bill_date))AS dt,& _ 
count(1)AS nbills,sum(amount)AS tamt,sum(iif(chk_free = 1,amount,0))AS pamt,& _
tamt-pamt AS totamt来自rec_all其中iif(rec_ref为null,0 ,rec_ref)<> 1和rw = 0和bill_date& _
'&格式之间(DTfrom( 0 )。值, yyyy / mm / dd)& '和' &格式(DTfrom( 1 )。值, YYYY / MM / DD )& '和co_code ='& CoCode& '& _
GROUP BY年(bill_date),月份(bill_date)





我的尝试:



跑步后发生此查询错误

 '  SELECT(month(bill_date)&'' & year(bill_date))AS dt,'





请帮帮我...

解决方案

1。 SELECT ...中的& 应为 +

2.您可能还需要将月份和年份转换为varchar避免错误将varchar值'3'转换为数据类型int时转换失败。



示例:



  SELECT   CONVERT  VARCHAR  2 ),MONTH(bill_date))+ ' < span class =code-string>,' +  CONVERT  VARCHAR  4 ),YEAR(bill_date))


I am using this SQL query,

("SELECT (month(bill_date) & ', ' & year(bill_date)) AS dt, " & _
"count(1) AS nbills, sum(amount) AS tamt, sum(iif(chk_free=1,amount,0)) AS pamt, " & _
"tamt-pamt AS totamt From rec_all Where iif(rec_ref is null,0,rec_ref)<>1 and rw = 0 and bill_date " & _
"between '" & Format(DTfrom(0).Value, "yyyy/mm/dd") & "' and '" & Format(DTfrom(1).Value, "yyyy/mm/dd") & "' and co_code='" & CoCode & "'" & _
"GROUP BY year(bill_date), month(bill_date)")



What I have tried:

After running this query error occurring

Incorrect syntax near 'SELECT (month(bill_date) & ', ' & year(bill_date)) AS dt, '.



Please help me...

解决方案

1. The & inside the "SELECT ... " should be +
2. You might also need to convert the month and year into varchar to avoid the error "Conversion failed when converting the varchar value '3, ' to data type int."

Example:

SELECT CONVERT(VARCHAR(2),MONTH(bill_date)) +', ' + CONVERT(VARCHAR(4),YEAR(bill_date))


这篇关于Syndax错误SQL查询执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆