开发者

Passing select statement as parameter to scalar function in SQL

开发者 https://www.devze.com 2023-04-12 13:55 出处:网络
I have scalar function which takes an integer as argument and return an integer too. I was trying t开发者_如何学Pythono use this function by passing a parameter as a select statement which looks like

I have scalar function which takes an integer as argument and return an integer too. I was trying t开发者_如何学Pythono use this function by passing a parameter as a select statement which looks like :

select dbo.scalarFunc(select si.ID from table1 si where version = 9)

It would not let me do it. I tried cast but still did not work. Can anyone tell me if I can use select inside like this or not?


I think a good way to write this is :

select dbo.scalarFunc(table1.ID) from table1 where version = 9

And if you want to use it later :

select * from table2 where ID = (select dbo.scalarFunc(table1.ID) from table1 where version = 9)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号