简体   繁体   中英

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)作为来自表的描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM