34,590
社区成员
发帖
与我相关
我的任务
分享
你最好把@str_sum定义为字符型
否则需要用到convert
select @str_sum=convert(int,substring(oper_rule,0,1)) from oper where
if @str_sum=1
Begin
.....
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
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
CREATE proc temp
@str_sum int
AS
begin
select oper_id from oper where substring(oper_rule,@str_sum,1)=1
end
CREATE procedure my_proc
@str_sum int
AS
begin
select * from oper where substring(oper_rule , @str_sum , 1) = '1'
end
go