简体   繁体   English

如何编写使用函数并将参数发送到函数的存储过程

[英]How to write stored procedure that used functions and sends parameters to functions

I need to write stored proc that gets a value from one table. 我需要编写从一个表获取值的存储过程。 Calculate new value according the retrieved value and sends the new value to a function. 根据检索到的值计算新值,并将新值发送到函数。

I have the following SQL statement: 我有以下SQL语句:

select mid from lastmid where region = '12'

Then I need to send this mid as a parameter to a function 然后我需要将此mid作为参数发送给函数

The function will generate new mid in the following fashion: 该函数将以以下方式生成新的中点:

  1. Get last 7 characters of mid and convert them to integer and increment that integer by 1 获取中位数的最后7个字符并将其转换为整数并将该整数加1

  2. I need to get New Sequence(Paded With 0's to give 7 Digits) With the 1st 9 Digits from the OLD mid 我需要从旧的中间获得第一个9位的新序列(填充0来给出7位)

and output the result 并输出结果

How can I do it? 我该怎么做?

Something like this: 像这样:

left(mid ,9) +  right('0000000' + cast(YourFunction(mid) as varchar), 7) as NewMid

Or, you could do it all in one line: 或者,您可以在一行中完成所有操作:

left(mid ,9) + right('0000000' + cast(cast(right(mid, 7) as int) + 1 as varchar), 7) as NewMid

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

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