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
精彩评论