我是Microsoft SQL Server的新手,但只需要对下面的代码进行一些改动。我正在尝试设置一个将用作超链接的字符串。它与我尝试向字符串中添加[fileID]
时不同,因为[fileID]
是整数。
我已经尝试过CAST
和CONVERT
,但是不确定确切地将其嵌入到此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
答案 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]