求一条sql语句 - MS-SQL Server / 基础类
cFilePath 字段中有如下值
lcz\0821\194712_01.jpg
lcz\0821\194712_06.jpg
.....................
现在要以这个字段的值去修改 flag 字段的值,cFilePath 字段满足条件 lcz\0821\194712,即“_”前内容相同时
环境SQL Server 2000
SQL code:
cFilePath like 'lcz\0821\194712%'
update tb set flag = left(cFilePath , charindex('-',cFilePath) - 1) where charindex('-',cFilePath) > 0
SQL code:
update tb set flag=right(col,charindex('_',reverse(col))-1)
SQL code:
create table tb(cFilePath varchar(30),flag varchar(30))
insert into tb values('lcz\0821\194712_01.jpg',null)
insert into tb values('lcz\0821\194712_06.jpg',null)
go
update tb set flag = left(cFilePath , charindex('_',cFilePath) - 1) where charindex('_',cFilePath) > 0
select * from tb
drop table tb
/*
cFilePath flag
------------------------------ ------------------------------
lcz\0821\194712_01.jpg lcz\0821\194712
lcz\0821\194712_06.jpg lcz\0821\194712
(所影响的行数为 2 行)
*/
SQL code
Code highl
相关问答:
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
请教高手:
以下是数据库中的三条记录,英文为字段名称
id planname TaskBeginTime Status
329 2010年03 ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......