使用列作为函数的输入参数并将结果添加到表中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用列作为函数的输入参数并将结果添加到表中相关的知识,希望对你有一定的参考价值。
[ConvertIPToLong是一个函数,我试图将#test1中的network列用作变量@cidrIP。我的结果应具有network列以及LowRange和HighRange列。
SELECT *
from #test1 as t1
Declare @CidrIP varchar(20)
Set @CidrIP = (select [network] from #test1)
Select dbo.[ConvertIPToLong](left(@CidrIP, patindex('%/%' , @CidrIP) - 1)) & (cast(4294967295 as bigint) ^ (Power(2, 32 - Cast(substring(@CidrIP, patindex('%/%' , @CidrIP) + 1, 2) as int)) - 1)) as LowRange
dbo.[ConvertIPToLong](left(@CidrIP, patindex('%/%' , @CidrIP) - 1)) & (cast(4294967295 as bigint) ^ (Power(2, 32 - Cast(substring(@CidrIP, patindex('%/%' , @CidrIP) + 1, 2) as int)) - 1)) + (Power(2, 32 - Cast(substring(@CidrIP, patindex('%/%' , @CidrIP) + 1, 2) as int)) - 1) as HighRange
答案
如果我了解你,我希望这样的事情可以工作:
Select dbo.[ConvertIPToLong](left([network], patindex('%/%' , [network]) - 1)) & (cast(4294967295 as bigint) ^ (Power(2, 32 - Cast(substring([network], patindex('%/%' , [network]) + 1, 2) as int)) - 1)) as LowRange
dbo.[ConvertIPToLong](left([network], patindex('%/%' , [network]) - 1)) & (cast(4294967295 as bigint) ^ (Power(2, 32 - Cast(substring([network], patindex('%/%' , [network]) + 1, 2) as int)) - 1)) + (Power(2, 32 - Cast(substring([network], patindex('%/%' , [network]) + 1, 2) as int)) - 1) as HighRange
from #test1
以上是关于使用列作为函数的输入参数并将结果添加到表中的主要内容,如果未能解决你的问题,请参考以下文章
Google Bigquery API:如何将结果查询添加到表中?