English 中文(简体)
我怎么把一个领域划为“......”?
原标题:How do I truncate a field and append "..." to it?

我试图宣读一份特定声明,将外地价值降至100个,并在最后添加......这样:

数百个自由会变成数百个 页: 1 这里是我所储存程序的选定说明。 这里的我 kind。 选择性的《东方木材协定》第(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
最佳回答

工作要做的是:

SELECT CASE 
           WHEN (LEN(Table1.LongText) < 100) THEN Table1.LongText
           ELSE SUBSTRING(Table1.LongText,1, 97) +  ... 
       END AS [Description]
FROM Table1;
问题回答

do you need all fields to have ... or only the ones who are actually bigger than 100 chars. If you need all, you can do something like:

select substring(name,0,97)+ ...  from...
;WITH x (d, tid, rn) AS
(
  SELECT SUBSTRING(Description, 1, 100) + CASE
    WHEN LEN(Description) > 100 THEN  ...  ELSE    END,
    TicketID, rn = ROW_NUMBER() OVER
    (PARTITION BY TicketID ORDER BY CommentDate DESC)
    FROM dbo.Comment
)
SELECT [TI].[TicketID], 
  CAST([TI].[Subject] AS VARCHAR(100)) [Subject], 
  [TA].[DueDate], 
  x.d 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]
    LEFT OUTER JOIN x ON TI.TicketID = x.tid
    AND x.rn = 1 -- oops, forgot this important part
    WHERE    [TI].[IsDeleted] = 0 AND
             [TS].[IsDeleted] = 0 AND
             [TS].[Status] =  Open  AND
             [TI].[AssigneeView] IS NULL AND
             [TI].[AssignedTo] = @AssignedTo;




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签