Are the NVARCHAR(MAX) column types necessary?
DECLARE @PropertyRepairsHistory Table
(
Jobnumber INT
, PropertyReference NVARCHAR (max) --
, JobTitle nvarchar (60)
, Priority nvarchar (20)
, JobType nvarchar (20)
, Contractorcode nvarchar (4)
, Contractor nvarchar (30)
, BilledValue MONEY
, ValuePaid MONEY
, StageHistDate DATE
, JobType2 NVARCHAR (20)
)
DECLARE @Property Table
(
PropertyRef nvarchar(max) --
, HouseNo NVARCHAR (4)
, AddressLine1 nvarchar (30)
, AddressLine2 nvarchar (30)
, AddressLine3 nvarchar (30)
, Postcode nvarchar (8)
, Officename nvarchar (max) --
, Officecode nvarchar (max) --
)
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden