开发者

How to change this mysql select into sql server select statement?

I use this mysql statement for开发者_如何学编程 concating description which has a length greater than 30..

select if (CHAR_LENGTH(description)>30,CONCAT(SUBSTRING(description,1,30),
'.....'),description) as description from table

How to change this mysql select into sql server select statement?


SELECT description = CASE 
    WHEN LEN(description) > 30 THEN SUBSTRING(description, 1, 30) + '...'
    ELSE description 
END
FROM table


SELECT LEFT(description,30) as description FROM table


Use a CASE statement; something like:

SELECT 
    CASE WHEN CHAR_LENGTH(description) > 30 
    THEN SUBSTRING(description,1,30) + '.....'
    ELSE description
    END as description 
FROM 
    table
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜