您的位置:首页 > 其它

sun服务器Solaris9安装

2008-07-10 08:47 246 查看
table a

id name

1  public/files/11.jpg,public/files/22.jpg

 

 

select id,name,firstname=case when len(SUBSTRING(name,0,charindex(',',name)))>1 then SUBSTRING(name,0,charindex(',',name)) else name end from a

 

 2、取到第一个,之前的与第一个,之后的

select
id,
name,
firstname=case when charindex(',',name)>0 then SUBSTRING(name,0,charindex(',',name))
else name end,
lastname=case when charindex(',',name)>0 then SUBSTRING(name,charindex(',',name)+1,(len(name) - charindex(',',name)))
else name end from a

 

sql函数 SUBSTRING、charindex、case when end

 

1、SUBSTRING()
SUBSTRING (<expression>, <starting_ position>, length)
返回从字符串左边第starting_ position 个字符起length个字符的部分

 

2、CHARINDEX()
返回字符串中某个指定的子串出现的开始位置。
CHARINDEX (<’substring_expression’>, <expression>)
其中substring _expression 是所要查找的字符表达式,expression 可为字符串也可为列名表达式。如果没有发现子串,则返回0 值。
此函数不能用于TEXT 和IMAGE 数据类型。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: