在存储过程中,如何得到字符串的第N位的值?

daqi2010 2009-03-13 11:06:27
表oper
oper_id oper_rule
1 001100
2 111110
现在想得到@str_sum位是否为1,如果是,则取出oper_id


CREATE proc ---
@str_sum int
AS
---怎么写
...全文
79 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouyongli41 2009-03-13
  • 打赏
  • 举报
回复
佩服一下
Zoezs 2009-03-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 daqi2010 的帖子:]
表oper
oper_id oper_rule
1 001100
2 111110
现在想得到@str_sum位是否为1,如果是,则取出oper_id


CREATE proc ---
@str_sum int
AS
---怎么写
[/Quote]

你最好把@str_sum定义为字符型
否则需要用到convert
select @str_sum=convert(int,substring(oper_rule,0,1)) from oper where
if @str_sum=1
Begin
.....
ChinaJiaBing 2009-03-13
  • 打赏
  • 举报
回复

if object_id('oper')is not null
drop table oper
if object_id('pro_c') is not null
drop procedure pro_c
create table oper (oper_id int,oper_rule int)
insert into oper select 1,'001100'
union all select 2,'111110'
go
create procedure pro_c (@str_sum int)
as
set nocount on
select * from oper where SUBSTRING( cast(oper_id as varchar(10)),@str_sum,1)=1
set nocount off
go
exec pro_c 1


oper_id oper_rule
----------- -----------
1 1100
ChinaJiaBing 2009-03-13
  • 打赏
  • 举报
回复

if object_id('oper')is not null
drop table oper
if object_id('pro_c') is not null
drop procedure pro_c
create table oper (oper_id int,oper_rule int)
insert into oper select 1,'001100'
union all select 2,'111110'
go
create procedure pro_c (@str_sum int)
as
set nocount on
select * from oper where oper_id=@str_sum
set nocount off
go
exec pro_c 1



oper_id oper_rule
----------- -----------
1 1100


yygyogfny 2009-03-13
  • 打赏
  • 举报
回复
高手就是高手,,那速度~~哎
yygyogfny 2009-03-13
  • 打赏
  • 举报
回复
create proc pr_test
@str_sum int
as
begin
select orer_id from oper where substring(oper_rule,@str_sum,1) = 1
end
cyz9977 2009-03-13
  • 打赏
  • 举报
回复

CREATE proc temp
@str_sum int
AS
begin
select oper_id from oper where substring(oper_rule,@str_sum,1)=1
end
dawugui 2009-03-13
  • 打赏
  • 举报
回复
CREATE  procedure my_proc 
@str_sum int
AS
begin
select * from oper where substring(oper_rule , @str_sum , 1) = '1'
end
go


ks_reny 2009-03-13
  • 打赏
  • 举报
回复
@str_sum 是如何得來的?
claro 2009-03-13
  • 打赏
  • 举报
回复
帮顶.
dawugui 2009-03-13
  • 打赏
  • 举报
回复
if substring(oper_rule , @str_sum , 1) = '1'
...

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧