日期:2014-05-18  浏览次数:20553 次

SQL语句中的if用法
问一个sql的较基础的问题,有一条语句“select   id,   topic,createdDate   from   news”我想得到一个这样的值:当topic的长度大于15时,得到Substring(topic,0,15)+ '…… '+createdDate的值,反之则得到topic+createdDate的值,怎么实现啊?谁能回答我的问题,我将送出10分。(十分抱歉,因为我刚刚注册)

------解决方案--------------------
....(case when len(topic) > 15 then .....else topic end)....

NND,手误
------解决方案--------------------
case .. when ..then ..
case .. when ..then ..
....
else ..
end
------解决方案--------------------
select case when len(topic)> 15 then
Substring(topic,0,15)+ '…… '+ltrim(createdDate)
else
topic+ltrim(createdDate)
end
结果
from news