设置超链接时将int转换为字符串

时间:2019-06-03 12:19:16

标签: sql-server

我是Microsoft SQL Server的新手,但只需要对下面的代码进行一些改动。我正在尝试设置一个将用作超链接的字符串。它与我尝试向字符串中添加[fileID]时不同,因为[fileID]是整数。

我已经尝试过CASTCONVERT,但是不确定确切地将其嵌入到此SELECT语句中的语法。只是错误的[fileID]部分。

ALTER PROCEDURE [dbo].[SelectBoxes2]
    @bootSaleDate DATE
AS
BEGIN
    SET NOCOUNT ON;

    SELECT DISTINCT 
        bootSaleDate,  
        '<br/><video width="100" height="250" src="catalog/videos/' + [fileId] + '" /></a>' AS strText, 
        fileID,
        '<a href="https://www.bargainboxes.co.uk/share-stall.aspx?oid='  + [fileID] + '">View Box</a>' AS link, 
        [buyPrice] AS buyPrice
    FROM 
        [tblItems]
    ORDER BY 
        bootSaleDate DESC
END

1 个答案:

答案 0 :(得分:1)

[fileId]是否可以为空?如果是这种情况,则应执行以下操作:

CAST(ISNULL([fileID],'') AS NVARCHAR(5)) 

请尝试以下操作:

SELECT DISTINCT bootSaleDate, '<br/><video width="100" height="250" src="catalog/videos/' + CAST(ISNULL([fileID],'') AS NVARCHAR(5)) + '" /></a>' as strText, fileID, '<a href="https://www.bargainboxes.co.uk/share-stall.aspx?oid='  + CAST(ISNULL([fileID],'') AS NVARCHAR(5)) + '">View Box</a>' as link, [buyPrice] as buyPrice FROM [tblItems]