1

I have scalar function which takes an integer as argument and return an integer too. I was trying to 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?

Ratan
  • 863
  • 5
  • 12
  • 28

1 Answers1

2

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)
Arnaud F.
  • 8,252
  • 11
  • 53
  • 102
  • If you want to use it later I'd suggest capturing it into a variable the first time instead. – Tom H Oct 10 '11 at 16:59