简体   繁体   English

SQL中的存储过程与子字符串一起使用

[英]Stored procedure in SQL used with substring

I have this stored procedure here: 我在这里有这个存储过程:

else if(substring(@SMS,1,1)='S')
begin
insert into WEB_POROSIA..SMS_SERVISI(IDTICKET, MBYLLUR) values(convert(int,substring(@SMS,2,len(@sms)-1)),1)
select @sms
end

What it does is: I send a SMS like this: 它的作用是:我发送这样的短信:

S 23 and in the database it saves the 23 value.. S 23并在数据库中保存23值。

Now, it works like this but not if I add a letter before: ie 现在,它的工作方式如下,但如果我之前添加一封信 ,则不会:

S B21 it should insert B21 to the table... S B21它应该将B21插入表格......

How to modify it? 如何修改?

values(convert(int,substring(@SMS,2,len(@sms)-1)),1)
               ^ Because you are converting it into int

You can convert into varchar if you to get B 如果你得到B,你可以convertvarchar

values(convert(varchar,substring(@SMS,2,len(@sms)-1)),1)

(Assuming you will alter the table and change the datetype from int to varchar ) (假设您将alter表并将datetypeint更改为varchar

You will need to remove the conversion to int: 您需要删除转换为int:

insert into WEB_POROSIA..SMS_SERVISI(IDTICKET, MBYLLUR) values(substring(@SMS,2,len(@sms)-1),1)

You may also need to modify the type on the target column if that is also using int. 如果也使用int,您可能还需要修改目标列上的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM