igelr
igelr

Reputation: 1731

object_id function is not working T-SQL

I have created a function named 'fname'.

 /*
create function fname(@ss int)
returns int
with schemabinding
as
begin 
return @ss
end
*/

object_id('fname')

Now I want to get its id using object_id function by specifying its name. SQL Server gives an error

Msg 102, Level 15, State 1, Line 11 Incorrect syntax near 'fname'.

Can anyone point what I am doing wrong? Thanks in advance.

Upvotes: 1

Views: 789

Answers (1)

Rami Bancosly
Rami Bancosly

Reputation: 434

You need to use the function under the SELECT statement

select object_id('fname')

I tried it and succeeded

create function fname(@ss int)
returns int
with schemabinding
as
begin 
return @ss
end

go
select  object_id('fname')

Upvotes: 1

Related Questions