我使用这个mysql语句来描述长度大于30的描述。
select if (CHAR_LENGTH(description)>30,CONCAT(SUBSTRING(description,1,30),
'.....'),description) as description from table
如何将这个mysql select改成sql server select语句?
答案 0 :(得分:1)
SELECT description = CASE
WHEN LEN(description) > 30 THEN SUBSTRING(description, 1, 30) + '...'
ELSE description
END
FROM table
答案 1 :(得分:0)
SELECT LEFT(description,30)作为描述FROM表
答案 2 :(得分:0)
使用CASE statement;类似的东西:
SELECT
CASE WHEN CHAR_LENGTH(description) > 30
THEN SUBSTRING(description,1,30) + '.....'
ELSE description
END as description
FROM
table