Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43187
  • 博文数量: 33
  • 博客积分: 1480
  • 博客等级: 上尉
  • 技术积分: 360
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-17 16:06
文章分类

全部博文(33)

文章存档

2009年(2)

2008年(31)

我的朋友
最近访客

分类: Mysql/postgreSQL

2008-04-21 13:29:06

问题1:

从一个字符串“2\33\445\12”分别取出2,33,445,12。
解决办法:利用parsename,replace两个函数,下面是示例
create table tb(f_qymc varchar(20))
insert into tb values('2/33/351/8')
insert into tb values('3/33/351/8')
insert into tb values('4/33/351/8')
insert into tb values('5/33/351/8')
insert into tb values('6/33/351/8')
go

select
PARSENAME(replace(f_qymc,'/','.'),4) col1,
PARSENAME(replace(f_qymc,'/','.'),3) col2,
PARSENAME(replace(f_qymc,'/','.'),2) col3,
PARSENAME(replace(f_qymc,'/','.'),1) col4
from tb

drop table tb

/*
col1 col2 col3 col4
---- ----- ------ ----
2 33 351 8
3 33 351 8
4 33 351 8
5 33 351 8
6 33 351 8

(所影响的行数为 5 行)

*/

问题2:


1,if @lx=1 or @lx=2 and @err =3//目的是得到条件是:@lx为1,或者@lx为2,并且在lx=1或者2的条件下@err必须为3
2,select * from xt_test where f_id=0 or f_id =1 and f_no =3
像上两种写法就会出现逻辑错误,这时就应该用括号加以限制,上述两条语句修改为:
if (@lx=1 or @lx=2) and @err=3
select * from xt_test whre (f_id=0 or f_id=1) and f_no=3

问题3:


让某一列的编号自动+1增长
语法:思路就是找到最大值,然后+1即可
select @bh=isnull(max(f_bhint),0)+1 from xt1_pgd
if @@error>0
  begin
     set @err=@@error
     rollback tran
     goto finish
end 

阅读(401) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~