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

时间:2022-07-21 16:42:13

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:

该函数将以下列方式生成新的mid:

  1. Get last 7 characters of mid and convert them to integer and increment that integer by 1

    获取mid的最后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

    我需要获得新序列(使用0给出7位数)和来自OLD mid的前9位数

and output the result

并输出结果

How can I do it?

我该怎么做?

1 个解决方案

#1


1  

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

#1


1  

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