SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + MASTER.NAME_FIRST + ' ' + MASTER.NAME_MI + '. ' + MASTER.NAME_LAST + ' ' + MASTER.NAME_SUFFIX + '., ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' +ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE ( NOT NAME_MI IS NULL) AND (NOT NAME_SUFFIX IS NULL)
UNION
SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + MASTER.NAME_FIRST + ' ' + MASTER.NAME_MI + '. ' + MASTER.NAME_LAST + ', ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' + ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE (NOT NAME_MI IS NULL) AND (NAME_SUFFIX IS NULL)
UNION
SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + MASTER.NAME_FIRST + ' ' + MASTER.NAME_LAST + ' ' + MASTER.NAME_SUFFIX + '., ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' + ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE (NAME_MI IS NULL) AND (NOT NAME_SUFFIX IS NULL)
UNION
SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + MASTER.NAME_FIRST + ' ' + MASTER.NAME_LAST + ', ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' + ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE (NAME_MI IS NULL) AND (NAME_SUFFIX IS NULL);
Public Function Proper(strName) As String
' T-SQL by Jens-Michael Lehmann (SQL Server Central)
' Converts McDonalds, O'Brian's, MacPherson's and the Jens-Michael's of the world
' But names followed by 2 or more initials ie brown ag are converted to Brown Ag
' Converted to VBA by Dennis Keeling Sept. 2005
'
Dim intStringLength As Integer
Dim intLoopCounter As Integer
Dim intWordCounter As Integer
Dim intWordStart As Integer
Dim strOutputString As String
Dim strCharAtPos1 As String * 1
Dim strCharAtPos2 As String * 2
Dim strCharAtPos3 As String * 3
If IsNull(strName) Then
Exit Function
End If
'Initialize
strOutputString = ""
intStringLength = Len(strName)
intLoopCounter = 1
intWordStart = 1
intWordCounter = 1
Do While intLoopCounter <= intStringLength
strCharAtPos1 = LCase(Mid(strName, intLoopCounter, 1))
strCharAtPos2 = LCase(Mid(strName, intLoopCounter, 2))
strCharAtPos3 = LCase(Mid(strName, intLoopCounter, 3))
' If at start of word then upper case the character
If intWordStart = 1 Then
strCharAtPos1 = UCase(strCharAtPos1)
intWordStart = 0
intWordCounter = 0
End If
If intWordStart > 1 Then
intWordStart = intWordStart - 1
End If
' If we encounter McSomething, Start a word
If strCharAtPos2 = "Mc" And intWordCounter = 0 Then
intWordStart = 2
End If
' If we encounter MacSomething, Start a word
If strCharAtPos3 = "Mac" And intWordCounter = 0 Then
intWordStart = 3
End If
' If we encounter a hochkomatta (high comma(German))
If strCharAtPos1 = "'" Then
intWordStart = 1
End If
' If we encounter a hyphen
If strCharAtPos1 = "-" Then
intWordStart = 1
End If
' If we encounter a comma
If strCharAtPos1 = "," Then
intWordStart = 1
End If
' If we encounter an underscore
If strCharAtPos1 = "_" Then
intWordStart = 1
End If
' If we encounter a dot
If strCharAtPos1 = "." Then
intWordStart = 1
End If
' If we encounter a space
If strCharAtPos1 = " " Then
intWordStart = 1
End If
' Form the output string
strOutputString = strOutputString & strCharAtPos1
intLoopCounter = intLoopCounter + 1
intWordCounter = intWordCounter + 1
Loop
Proper = strOutputString
End Function
you require a proper function that you can embed in the queries driving the reports.
RG said:You mean like:
+ StrConv([MASTER].[NAME_LAST] , vbProperCase) + ...
SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + StrConv([MASTER].[NAME_FIRST] , vbProperCase) + ' ' + MASTER.NAME_MI + '. ' + StrConv([MASTER].[NAME_LAST] , vbProperCase) + ' ' + StrConv([MASTER].[NAME_SUFFIX] , vbProperCase) + '., ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' +ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE ( NOT NAME_MI IS NULL) AND (NOT NAME_SUFFIX IS NULL)
UNION
SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + StrConv([MASTER].[NAME_FIRST] , vbProperCase) + ' ' + MASTER.NAME_MI + '. ' + StrConv([MASTER].[NAME_LAST] , vbProperCase) + ', ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' + ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE (NOT NAME_MI IS NULL) AND (NAME_SUFFIX IS NULL)
UNION
SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + StrConv([MASTER].[NAME_FIRST] , vbProperCase) + ' ' + StrConv([MASTER].[NAME_LAST] , vbProperCase) + ' ' + StrConv([MASTER].[NAME_SUFFIX] , vbProperCase) + '., ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' + ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE (NAME_MI IS NULL) AND (NOT NAME_SUFFIX IS NULL)
UNION
SELECT MASTER.KEY, RANK.LONG_RANK + ' ' + StrConv([MASTER].[NAME_FIRST] , vbProperCase) + ' ' + StrConv([MASTER].[NAME_LAST] , vbProperCase) + ', ' + ORDERS_TBL.LAST_FOUR + ', ' + 'United States ' + MASTER.SERVICE + ', ' + ORDERS_TBL.FROM_DATE + ' to ' + ORDERS_TBL.TO_DATE + ', ' + 'SHAPE, ' + AWD_REASON.AWD_RSN_LONG + ' Award.' AS MAGIC, AWARD_TYPE.AWD_TYP_LONG, MASTER.ORDERS_NUMBER, MASTER.ORDERS_DATE
FROM (((RANK RIGHT JOIN MASTER ON RANK.SHORT_RANK = MASTER.RANK) LEFT JOIN AWARD_TYPE ON MASTER.APVD_AWD = AWARD_TYPE.AWD_TYP_SHRT) LEFT JOIN AWD_REASON ON MASTER.AWD_REASON = AWD_REASON.AWD_RSN_SHORT) LEFT JOIN ORDERS_TBL ON MASTER.SSN = ORDERS_TBL.SSN
WHERE (NAME_MI IS NULL) AND (NAME_SUFFIX IS NULL);
to use a function in a query just replace the column name like this
pCaseroper(yourSurname)
this function will handle all the mcs, macs etc.
or if you write sql Proper(yoursurname) as PCase