Trying to pull JamesK and ScottPletcher back in, I agree with Kristen that losing things out at the end of the line is a problem, but without the ability to get tools, my solution is line continuation:
IF OBJECT_ID(‘tempdb..#Denials’) IS NOT NULL
DROP TABLE #Denials
GO
CREATE TABLE #Denials
(
rejection_code CHAR(10) NULL,
rej_cd_description CHAR(40) NULL,
rsn_ds CHAR(40) NULL,
payment_date DATETIME NULL,
rejected_amount MONEY NULL,
co_insurance_amount MONEY NULL,
total MONEY NULL
)
INSERT INTO #Denials
(
rejection_code,
rej_cd_description,
rsn_ds,
payment_date,
rejected_amount,
co_insurance_amount,
total
)
SELECT
Tpb483.rejection_code AS [Rejection Code],
Tpb483.rej_cd_description AS [Rejection Code Description],
Tpb483.rsn_ds AS [Rejection Reason],
Tpb484.payment_date AS [Payment Date],
ISNULL(Tpb484.rejected_amount, 0) AS Rejected,
ISNULL(Tpb484.co_insurance_amount, 0) AS [Co-insurance],
(SELECT "Total" =
ISNULL(Tpb484.noncovered_amount, 0) +
ISNULL(Tpb484.rejected_amount, 0)) AS [Total Rejection]
FROM
TPB484_ER_FILE_PATIENT_HISTORY AS Tpb484
ON Tpb484.ivo_int_id = Tpb311.ivo_int_id
AND Tpb484.plan_int_id = Tpb311.plan_int_id
AND Tpb484.pyr_seq_no = Tpb311.pyr_seq_no
JOIN
TPB486_REASON_HISTORY_DETAIL AS Tpb486
ON Tpb484.er_file_pat_hst_int_id = Tpb486.er_file_pat_hst_int_id
JOIN
TPB483_ER_REJECTION_CODES AS Tpb483
ON Tpb486.rsn_cod_int_id = Tpb483.er_rejection_codes_int_id
AND Tpb483.rej_cd_description <> '16'
WHERE
Tpb483.rej_cd_description = 'DENIED'
AND
ISNULL(Tpb484.noncovered_amount, 0) +
ISNULL(Tpb484.rejected_amount, 0) > 250.00
)
Although ragged when pasted in, the aliases are set on the closing brace at an exact distance easily viewable on a 'small' monitor. I match the equals signs, the assignment column (tab is my friend!) and explicitly define everything for readability. I admit that the 'INSERT INTO' block may be overkill, but six months from now when a new feature needs added, I will be less confused.