duanque2413 2017-02-02 19:00
浏览 366

Laravel SQL Server,Concat结果?

I would like to get an combined string with Laravel using DB:raw(). I am using a SQL Server 2012 in Backgroud, but i am unable to the the following string scheme.

mm-yyyy (for example, 11-2016)

Its working with:

DB::raw('CONVERT(varchar(2),DATEPART(MM, invoices.invoice_date),100) + CONVERT(varchar(4),DATEPART(YY, invoices.invoice_date),100) AS invoice_month'),

to get 112016, but when ill try with:

DB::raw('CONVERT(varchar(2),DATEPART(MM, invoices.invoice_date),100) + "-" + CONVERT(varchar(4),DATEPART(YY, invoices.invoice_date),100) AS invoice_month'),

ill get an fatal PDO Exception.

Any ideas?

  • 写回答

1条回答 默认 最新

  • doupiai5597 2017-02-02 19:15
    关注

    Instead of double quotes around the dash, try it with two single quotes around the dash:

    DB::raw('CONVERT(varchar(2),DATEPART(MM, invoices.invoice_date),100) + ''-'' + CONVERT(varchar(4),DATEPART(YY, invoices.invoice_date),100) AS invoice_month')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计