转换失败的 varchar 值

Conversion Failed varchar Value

   SELECT  
    ClientID,
    ProfileID as [Profile ID],
    Title,Name as [First Name],
    Surname as [Last Name],
    Lender,
    Product,
    LoanAmount as [Loan Amount],
    DateCompleted as [Mortgage Completed Date],
    Source as [Lead Source],
    ERC as [Erc Date],
    Casetype as [Case Type],
    email,
    HouseNameNum as Street,
    Address1 as Street, 
    Address2 as Street,
    Town as City,
    (postcode1 + postcode2) as Postcode,
    CAST('http://172.16.200.119/BPSAdmin/Legacy/CommTracking.aspx?ClientId='+ ClientID AS VARCHAR(100)) as [Perspectives Comms]
FROM Datatable

我收到的错误是:

Conversion failed when converting the varchar value

'http://172.16.200.119/BPSAdmin/Legacy/CommTracking.aspx?ClientId=' 数据类型为 int

ClientID 是一个 INT,但是,我想在字段的开头添加一些字符串以创建指向客户文件的超链接。

关于如何解决这个问题的任何建议 干杯

我认为您需要自己显式转换客户 ID 列,因此只需将您的转换转移过来:'http://172.16.200.119/BPSAdmin/Legacy/CommTracking.aspx?ClientId=' + cast(clientid as varchar)

在强制转换之外添加 url,这样它的强制转换函数就可以工作,并将 Int 转换为 varchar

因为 Int 和 string 不能连接,所以需要相同的数据类型。

SELECT  
    ClientID,
    ProfileID as [Profile ID],
    Title,Name as [First Name],
    Surname as [Last Name],
    Lender,
    Product,
    LoanAmount as [Loan Amount],
    DateCompleted as [Mortgage Completed Date],
    Source as [Lead Source],
    ERC as [Erc Date],
    Casetype as [Case Type],
    email,
    HouseNameNum as Street,
    Address1 as Street, 
    Address2 as Street,
    Town as City,
    (postcode1 + postcode2) as Postcode,
    'http://172.16.200.119/BPSAdmin/Legacy/CommTracking.aspx?ClientId='+ CAST( ClientID AS VARCHAR(100)) as [Perspectives Comms]
FROM Datatable