-1

I'm having a problem in concatenating 2 columns in my sql. Can someone check what went wrong in my concat statement.

Query:

Public Function getStudents(ByVal oStudentsBO As StudentsBO) As DataTable
    dt = New DataTable
    sql = "SELECT [KY_ID_NUM] as [ID Num], [NM_NICK] as [Nick Name], [CD_AGE_GROUP] as [Age Group], " &
          "[NM_LAST] as [Last Name], [NM_FIRST] as [First Name], " &
          "CONCAT(NM_GFIRST, NM_GLAST) FROM [tblStudents] " &
          "WHERE [NM_FIRST] Like '%" & oStudentsBO.NM_FIRST & "%'" &
          "OR [NM_NICK] LIKE '%" & oStudentsBO.NM_NICK & "%'" &
          "OR [NM_LAST] Like '%" & oStudentsBO.NM_LAST & "%'"
    dt = oDA.getDataTable(sql)
    Return dt
End Function

Error:

error report

Community
  • 1
  • 1
Aldy
  • 83
  • 1
  • 10

1 Answers1

1

MS Access doesn't have a function CONCAT. Instead, you must use a string concatenation:

Public Function getStudents(ByVal oStudentsBO As StudentsBO) As DataTable
    dt = New DataTable
    sql = "SELECT [KY_ID_NUM] as [ID Num], [NM_NICK] as [Nick Name], [CD_AGE_GROUP] as [Age Group], " &
          "[NM_LAST] as [Last Name], [NM_FIRST] as [First Name], " &
          " [NM_GFIRST] & [NM_GLAST] FROM [tblStudents] " &
          "WHERE [NM_FIRST] Like '%" & oStudentsBO.NM_FIRST & "%'" &
          "OR [NM_NICK] LIKE '%" & oStudentsBO.NM_NICK & "%'" &
          "OR [NM_LAST] Like '%" & oStudentsBO.NM_LAST & "%'"
    dt = oDA.getDataTable(sql)
    Return dt
End Function
shadowsheep
  • 14,048
  • 3
  • 67
  • 77