I declare it as:
declare @SQL2 varchar(max)=
I could be wrong, but when this is the last statement, code is fine:
blah blah blah
AvgRevenueBooked
INTO ##Confidence3
FROM ##Confidence2
ORDER BY OptimizationGroupID, ProductID'
EXEC(@SQL2)
but when I make it:
blah blah blah
AvgRevenueBooked
INTO ##Confidence3
FROM ##Confidence2
ORDER BY OptimizationGroupID, ProductID
SELECT
C.ProductID,
C.OptimizationGroupID,
C.TreatmentOrdinal,
--C.CalculatedFromText,
COALESCE(C.PricingType, CT.CalculatedFromText) AS PricingType,
C.CurrencyCode,
C.Origin,
C.Destination,'+
case when @passangers='Y' then ' C.Passangersgroup' else '' end +
case when @fareclass='Y' then ' C.Fareclass' else '' end +
case when @ispriorbooking='Y' then ' C.IsPriorBooking' else '' end +'
INTO ##PricingTypes
FROM @CalculatedFromText CT
LEFT JOIN ##Confidence2 C
ON C.CalculatedFromText = CT.CalculatedFrom'
EXEC(@SQL2), it says there is an error right around C.ProductID, (in this case it says at the ',', but if I delete things from previous statement, the error gets moved up relative to how many characters I delete) which is right where the 8000 character mark is (when I print the @SQL2).
Shouldnt I be able to have unlimited # of characters (reasonably) with an exec statement?