Raw Query Laravel 5.6, SQL SERV
ต้องการใส่เครื่องหมาย Single Quotes between '2018-04-01' and '2018-04-30' เพราะถ้าไม่มีเครืองหมาย ' เวลา query จะไม่มีข้อมูลออกมาเลย
Code (PHP)
แบบที่ 1
->whereBetween ('opdmas.VisitDate',[(convert(date,str_replace("*", "'",'*2018-04-01*'))),(convert(date,str_replace("*","'",'*2018-04-30*')))])
Error
Call to undefined function App\Http\Controllers\Report\convert()"
Code (PHP)
แบบที่ 2
->whereBetween ('opdmas.VisitDate',[str_replace("*", "'",'*2018-04-01*'),str_replace("*","'",'*2018-04-30*')])
Error
Conversion failed when converting date and/or time from character string......
output: [opdmas].[VisitDate] between '2018-04-01' and '2018-04-30'
Code (PHP)
แบบที่ 3
->whereBetween ('opdmas.VisitDate',["'2018-04-01'","'2018/04/30'"])
Error
Conversion failed when converting date and/or time from character string.
output : opdmas].[VisitDate] between '2018-04-01' and '2018/04/30'
ก็เลยลองเอาฟิลด์ master.VisitDate ออก มันก็ฟ้องทันทีเลยคะ Invalid column name 'datetime' Code (PHP)
"SQLSTATE[42S22]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid column name 'datetime'.
ถ้าใส่แบบนี้ ->whereBetween('master.VisitDate','datetime',array('2018-04-01','2018-04-30'))
Error เพราะมันยอมได้แค่ค่าเดียวตาม function whereBetween
Code (PHP)
public function whereBetween($column, array $values, $boolean = 'and', $not = false){
.
.
}
Type error: Argument 2 passed to Illuminate\Database\Query\Builder::whereBetween() must be of the type array, string given, called in D:\Apache24\htdocs\Laravel...on line 23
Code (PHP)
public function TodayDetail()
{
//RAW QUERIES
$TodayDetail = DB::table('DB_TEST.dbo.HNOPD_master as master')
->join('DB_TEST.dbo.PRESCRIP as prescrip',
function ($join){
$join->on('master.VN','=','prescrip.VN')
->on('master.VisitDate','=','prescrip.VisitDate');
})
->join(
'DB_TEST.dbo.Cconfig as config'
,'prescrip.Clinic','=','config.code'
)
->select(DB::raw('count(master.VN) as VN','count(DISTINCT prescrip.Doctor) as Doctor')
,'master.VisitDate'
,'prescrip.Clinic'
,'config.LocalName'
)
->where([['master.sxl','=','0'],['prescrip.Clinic','=',"'AO'"],['config.CtrlCode','=','12345']])
->whereBetween('master.VisitDate','datetime',array('2018-04-01','2018-04-30'))
->get();
}