So I want to prepare a list to place into a combobox with laravel and I wanted to use concatenate to join the value of 3 columns and I can achieve that with this
public function deviList() {
return Device::select(DB::raw('CONCAT(DESC, OS, OS_V) AS FullDesc'), 'DEVI_ID')
->where('STATUS', 2)
->orderBy('DESC')
->lists('FullDesc', 'DEVI_ID');
}
However it'd be better to have a space or slash separating the values of the columns so I did it like this, same as some people recomended in some other places:
public function deviList() {
return Device::select(DB::raw('CONCAT(DESC," ",OS," ",OS_V) AS FullDesc'), 'DEVI_ID')
->where('STATUS', 2)
->orderBy('DESC')
->lists('FullDesc', 'DEVI_ID');
}
However I get an error saying SQLSTATE[42S22]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid column name ' ' (So I'm guessing unlike the examples given elsewhere, those separations get read as if they were columns?) So how can I concatenate with some sort of separation?
If your SQL Server has QUOTED_IDENTIFIER
turned on, then the double quotes will be used to identify objects, not string literals. In this case, " "
would not be a string representing a space, it would be an object (column) represented by a space, which doesn't exist.
Try switching the quotes in your SQL statement:
public function deviList() {
return Device::select(DB::raw("CONCAT(DESC,' ',OS,' ',OS_V) AS FullDesc"), 'DEVI_ID')
->where('STATUS', 2)
->orderBy('DESC')
->lists('FullDesc', 'DEVI_ID');
}
QUOTED_IDENTIFIER
docs here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With