如何编写使用函数并将参数发送给函数的存储过程
How to write stored procedure that used functions and sends parameters to functions
我需要编写从 table 获取值的存储过程。根据检索到的值计算新值并将新值发送给函数。
我有以下 SQL 声明:
select mid from lastmid where region = '12'
然后我需要将这个 mid 作为参数发送给函数
该函数将按以下方式生成新的中间值:
获取 mid 的最后 7 个字符并将它们转换为整数并将该整数递增 1
我需要得到新的序列(用 0 填充以给出 7 位数字)从旧的中间开始的第 9 位数字
并输出结果
我该怎么做?
像这样:
left(mid ,9) + right('0000000' + cast(YourFunction(mid) as varchar), 7) as NewMid
或者,您可以在一行中完成所有操作:
left(mid ,9) + right('0000000' + cast(cast(right(mid, 7) as int) + 1 as varchar), 7) as NewMid
我需要编写从 table 获取值的存储过程。根据检索到的值计算新值并将新值发送给函数。
我有以下 SQL 声明:
select mid from lastmid where region = '12'
然后我需要将这个 mid 作为参数发送给函数
该函数将按以下方式生成新的中间值:
获取 mid 的最后 7 个字符并将它们转换为整数并将该整数递增 1
我需要得到新的序列(用 0 填充以给出 7 位数字)从旧的中间开始的第 9 位数字
并输出结果
我该怎么做?
像这样:
left(mid ,9) + right('0000000' + cast(YourFunction(mid) as varchar), 7) as NewMid
或者,您可以在一行中完成所有操作:
left(mid ,9) + right('0000000' + cast(cast(right(mid, 7) as int) + 1 as varchar), 7) as NewMid