首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL语句中的if用法解决方案

2012-01-16 
SQL语句中的if用法问一个sql的较基础的问题,有一条语句“selectid,topic,createdDatefromnews”我想得到一个

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

热点排行