I want to write an SQL query using MS access, which calculates a serial number using a VBA Function.
I have a big "samplebasicinformation" table which has lots of foreign keys and want to use the text fields in the foreign tables to create a text-based serial number.
I want the first field of the query to abbreviate a few text fields from other tables, then concatenate them and create this serial number.
In order to abbreviate the text fields I have the following function:
Function GetFirstLetters(rng As String)
Dim arr
Dim I As Long
arr = VBA.Split(rng, " ")
If IsArray(arr) Then
For I = LBound(arr) To UBound(arr)
GetFirstLetters = GetFirstLetters & Left(arr(I), 1)
Next I
Else
GetFirstLetters = Left(arr, 1)
End If
End Function
I've tried the below SQL to achieve this but failed due to syntax error.
SELECT
(getfirstletters(select sl.locationname from samplebasicinformation as sbi join samplelocation as sl
on sbi.samplelocationid = sl.samplelocationid)),
samplebasicinformationid
from samplebasicinformation as sbi1
Would anyone be able to offer some advice?