我試圖找出一個選擇語句,將字段值截斷爲100個字符,並將其添加到它的末尾如此喜歡:如何截斷一個字段並在其後面添加「...」?
HundredLetterSentence變成了HundredLetter Sen ......或類似的東西。這是我的存儲過程中的select語句。我有點從這裏陷入困境。 Select TOP(1)描述是我想要截斷的地方。
SELECT [TI].[TicketID]
, CAST([TI].[Subject] AS VARCHAR(100)) [Subject]
, [TA].[DueDate]
, CAST(
( SELECT
TOP(1) SUBSTRING(Description, 0, 100)
FROM Comment
WHERE TicketID = [TI].[TicketID]
ORDER BY CommentDate DESC
) AS VARCHAR(100)
) AS [Description]
FROM [dbo].[Ticket] [TI]
INNER JOIN [dbo].[Task] [TA]
ON [TI].[TicketID] = [TA].[TicketID]
INNER JOIN [dbo].[Task_Status] [TS]
ON [TA].[StatusID] = [TS].[StatusID]
WHERE [TI].[IsDeleted] = 0
AND [TS].[IsDeleted] = 0
AND [TS].[Status] = 'Open'
AND [TI].[AssigneeView] IS NULL
AND [TI].[AssignedTo] = @AssignedTo
糟糕 - 重新閱讀帖子,看到你說「截斷爲100個字符」,我做了100個字符的總長度:)你可以用100替換97(或者任何想要剪輯的長度 –