日期:2014-05-19  浏览次数:20558 次

求一个简单的存储过程~
5位的数据,前三位为数字,后二位为字母,如123AB
要用存储过程进行转换,规则为,前三位数字减19,后二位A对应S,B对应P
123AB转换后为104SP

谢谢了~

------解决方案--------------------
CREATE PROCEDURE dbo.Convar
@aa nvarchar(5)
AS
begin
select Convert(nvarchar,left(@aa,3)-19)+replace(replace(right(@aa,2), 'A ', 'S '), 'B ', 'P ')
end
GO



------解决方案--------------------
create proc prc(@data varchar(10))
as
begin
declare @s varchar(10)
set @s= ' '
set @s=cast(cast(left(@data,3) as int)-19 as varchar)
if substring(@data,4,1)= 'A ' and substring(@data,5,1)= 'B '
set @s=@s+ 'SP '
select @s
end
go

exec prc '123AB '
--104SP
------解决方案--------------------
select str(left( '123AB ',3)-19)+right(replace(replace( '123AB ', 'A ', 'S '), 'B ', 'P '),2)
------解决方案--------------------
create proc pro_a @b varchar(20),@c varchar(20) output as
set @c=rtrim(rtrim(left(@b,3))-19)+replace(replace(right(@b,2), 'A ', 'S '), 'B ', 'P ')

declare @bb varchar(20)
exec pro_a '123AB ',@bb output
select @bb

104SP