title: CardinalityEstimate query warning
body: <p>I have a database view (SQL Server 12.0.2269) which summarizes data from a number of tables.  I have just noticed a warning on the Execution plan (though it has probably always been there):</p>
  
  <p>Type conversion in expression (CONVERT(varchar(30),[t].[RoleID],0)) may affect "CardinalityEstimate" in query plan choice</p>
  
  <p>The actual query code it refers to is for one result field:-</p>
  
  <pre><code>(SELECT 
      '|' + CAST(t.RoleID AS varchar)
   FROM Tag t
   WHERE t.SourceID = lb.ID
   FOR XML PATH('') ) + '|'
   AS TagIDs,
  </code></pre>
  
  <p>which produces a list of separated IDs like this '|10|11|12|'.
  RoleID is a tinyint; is part of a compound primary key and is also a foreign key.</p>
  
  <p>Being tinyint, it can never be longer than 3 chars but I guess the varchar(30) is a default.</p>
  
  <p>Can I safely ignore this warning? </p>
  
  <p>The full query is</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>CREATE VIEW [dbo].[LegalBodyReferenceData] AS
  SELECT
   lb.ID,
   lb.DisplayName,
   lb.BirthDate,
   lb.DeathDateAndFlag as DeathDate,
   
   ti.Description AS Title,
   p.FirstNames,
   p.Surname,
   
   lb.Telephone,
   lb.Email,
   
   a.Street,
   a.Town,
   a.Region,
   a.Postcode,
   a.Country,
   
   COALESCE(cf1.ID, ccf.ID) AS ClientFileID,
   COALESCE(cf1.FileStatusID, cf2.FileStatusID) AS ClientFileStatusID,
   COALESCE(cf1.AdviserID, cf2.AdviserID) AS ClientFileAdviserID,
   COALESCE(cf1.DisplayName, cf2.DisplayName) AS ClientFileDisplayName,
   
   ISNULL(CAST(CASE WHEN p.ID IS NOT NULL THEN 1 ELSE 0 END AS bit), 0) AS IsPerson,
   ISNULL(CAST(CASE WHEN co.ID IS NOT NULL THEN 1 ELSE 0 END AS bit), 0) AS IsCorporate,
   ISNULL(CAST(CASE WHEN prov.ID IS NOT NULL THEN 1 ELSE 0 END AS bit), 0) AS IsProvider,
   ISNULL(CAST(CASE WHEN Trust.ID IS NOT NULL THEN 1 ELSE 0 END AS bit), 0) AS IsTrust,
   ISNULL(CAST(CASE WHEN cbp.ID IS NOT NULL THEN 1 ELSE 0 END AS bit), 0) AS IsCorporateBenefitProvider,
   (SELECT 
    '|' + CAST(t.RoleID AS varchar)
   FROM Tag t
   WHERE t.SourceID = lb.ID
   FOR XML PATH('') ) + '|'
    AS TagIDs,
   NULL AS Tags,
   
   c.MaritalStatusID,
   p.Gender,
   u.ID AS UserID,
   ISNULL(CAST(CASE WHEN ad.ID IS NOT NULL THEN 1 ELSE 0 END AS bit), 0) AS IsAdviser,
   prov.UniqueIdentifier AS ProviderCode,
   CAST(c.DisplayOrder AS tinyint) AS ClientDisplayOrder,
  
   p.InformalSalutation AS InformalSalutation,
   ISNULL(CAST(CASE WHEN Trust.IsSimpleTrust IS NOT NULL THEN 1 ELSE 0 END AS bit), 0) AS IsSimpleTrust
  
  FROM LegalBody lb
  LEFT JOIN Address a ON a.ID = lb.PrimaryAddressID
  LEFT JOIN Person p ON p.ID = lb.ID
  LEFT JOIN Title ti ON ti.ID = p.TitleID
  LEFT JOIN Client c ON c.ID = lb.ID
  LEFT JOIN ClientFile cf1 ON cf1.ID = c.PrivateClientFileID
  LEFT JOIN Corporate co ON co.ID = lb.ID
  LEFT JOIN Provider prov ON prov.ID = co.ID
  LEFT JOIN Trust ON Trust.ID = lb.ID
  LEFT JOIN CorporateBenefitProvider cbp on cbp.ID = lb.ID
  LEFT JOIN CorporateClientFile ccf ON ccf.CorporateID = co.ID
  LEFT JOIN ClientFile cf2 ON cf2.ID = ccf.ID
  LEFT JOIN [User] u ON u.PersonID = p.ID
  LEFT JOIN [Adviser] ad ON ad.ID = u.ID</code></pre>
  </div>
  </div>
  </p>