This is my query:
SELECT at.AssetTag,
dp.Custodian,
CASE WHEN PATINDEX('%_%', dp.Custodian) = '0'
THEN dp.Custodian
ELSE RIGHT(LTRIM(RTRIM(dp.Custodian)),LEN(LTRIM(RTRIM(dp.Custodian)) - PATINDEX('%_%', dp.Custodian))) END AS FirstName,
CASE WHEN PATINDEX('%_%', dp.Custodian) = '0'
THEN ''
ELSE LEFT(dp.Custodian, PATINDEX('%_%', dp.Custodian)-1) END AS LastName, RIGHT(at.Assettag,3) AS MediaTypeSuffix
FROM tblAssetTracking at (NOLOCK)
INNER JOIN tblDiscoveryProcessing dp (NOLOCK) ON dp.FKAsset = at.ID
WHERE dp.Custodian Is Not Null
When I run it I get an error "Conversion failed when converting the nvarchar value 'XXX' to data type int" (xxx is an actual value I had to replace). Can anyone help, please? Ps. I hope the statement went into the code block right. Apparently, I don't understand how to paste code in properly.
Thanks!