Note: The SQL account which invokes the GetSalutation function must have sufficient rights to the database. Users other than the owner must be granted EXECUTE permission on a function (if the function is scalar-valued) before they can use it in a Transact-SQL statement. If the function is table-valued, the user must have SELECT permissions on the function before referencing it.
SELECT R.ID, R.Constituent_ID, R.FIRST_NAME, R.LAST_NAME, R.[DATE_LAST_CHANGED],

case
when R.PRIMARY_ADDRESSEE_EDIT = -1
then R.PRIMARY_ADDRESSEE
else
dbo.GetSalutation(R.PRIMARY_ADDRESSEE_ID,R.ID,'',0,0,0,getdate())
end as 'PRIMARY_ADDRESSEE',

case
when R.PRIMARY_SALUTATION_EDIT = -1
then R.PRIMARY_SALUTATION
else
dbo.GetSalutation(R.PRIMARY_SALUTATION_ID,R.ID,'',0,0,0,getdate())
end as 'PRIMARY_SALUTATION',

ADDSAL_TYPE.LONGDESCRIPTION as 'ADDSAL_TYPE_DESC',CS.SALUTATION_ID, CS.SEQUENCE, CS.EDITABLE,

case
when CS.EDITABLE = -1
then CS.SALUTATION
else
dbo.GetSalutation(CS.SALUTATION_ID,R.ID,'',0,0,0,getdate())
end as 'SALUTATION_CORRECT',
CS.SALUTATION as 'SALUTATION_FIELD_INCORRECT'

FROM [RECORDS] R
left outer join CONSTITUENT_SALUTATION AS CS ON R.ID=CS.CONSTIT_ID
left outer join TABLEENTRIES AS TE ON R.TITLE_1=TE.TABLEENTRIESID
left outer join TABLEENTRIES ADDSAL_TYPE on CS.SAL_TYPE=ADDSAL_TYPE.TABLEENTRIESID

ORDER BY CS.SEQUENCE

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Structured Query Language and the tools used to create and modify SQL statements and Crystal Reports. Our Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.