2

The query I have written is:

Yii::app()->db->createCommand($sql)->queryAll();

where

$sql= 'SELECT `EMAIL` as `EMAIL_ADDRESS`, concat(`FIRST_NAME`, `' '` ,`LAST_NAME`) as `FULL_NAME`, `PHONE_NUMBER` FROM `claim_request`';

What I want to do is FULL_NAME = Mark Taylor. But CDbcommand is not adding space it gives the output as FULL_NAME = MarkTaylor.

tadman
  • 208,517
  • 23
  • 234
  • 262
abhit
  • 973
  • 3
  • 17
  • 40

2 Answers2

2

As a side note CONCAT will do what you want but it has some limitation as it will give correct result only when both FIRST_NAME,LAST_NAME exist in database if any one is NULL then it will give null in result so i suggest to use CONCAR_WS for this if you think that LAST_NAME may be empty for some users

$sql= 'SELECTE MAIL as EMAIL_ADDRESS, CONCAT_WS(" ",FIRST_NAME,,LAST_NAME) as FULL_NAME, PHONE_NUMBER FROM claim_request';

for more info please read http://www.w3resource.com/mysql/string-functions/mysql-concat_ws-function.php

Also see this question for more info MySQL CONCAT returns NULL if any field contain NULL

Community
  • 1
  • 1
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
1

Use this,

$sql= 'SELECTE MAIL as EMAIL_ADDRESS, concat(FIRST_NAME," ",LAST_NAME) as FULL_NAME, PHONE_NUMBER FROM claim_request';

Instead of single quotation mark, you can use double quotation mark...

Kishor
  • 200
  • 13