Concatenate 2 columns Android SQLite



到目前为止,我有这个:

    Cursor cursor = dbHelper.getAllPatients();
    String[] data = new String[]{DBHelper.KEY_LNAME, 
            DBHelper.KEY_FNAME, DBHelper.KEY_DIAGNOSIS};
    int[] to = new int[] {R.id.fullname, R.id.diagnosis};
    dataAdapter = new SimpleCursorAdapter(this, R.layout.custom_row, cursor, data, to, 0);
    dbHelper.close();
    lv.setAdapter(dataAdapter);
    lv.setTextFilterEnabled(true);

getAllPatients()方法

  public Cursor getAllPatients()
{
    Cursor localCursor = 
            this.myDataBase.query(DB_TABLE, new String[] { 
                    KEY_ID, KEY_FNAME, KEY_LNAME, KEY_DIAGNOSIS }, null, null, null, null, null);
    if (localCursor != null)
      localCursor.moveToFirst();
    return localCursor;
}

我希望列FNAMELNAME。你有这个主意吗?我非常感谢你的帮助。谢谢

查询时执行以下操作

Cursor localCursor = 
        this.myDataBase.query(DB_TABLE, new String[] { 
                KEY_ID, KEY_FNAME +"||"+ KEY_LNAME, KEY_DIAGNOSIS }, null, null, null, null, null);

当使用适配器分配值时,如下所示

String[] data = new String[]{DBHelper.KEY_LNAME +"||"+ DBHelper.KEY_FNAME, DBHelper.KEY_DIAGNOSIS};
int[] to = new int[] {R.id.fullname, R.id.diagnosis};

尝试这个

SELECT CONCAT(ColA, ColB) AS ColC FROM Table

String query = "select" +ColA+"+"+ColB +"as CompleteAddress from YourTable";

最新更新