Click here to Skip to main content
15,906,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My table(emp):

Column Datatype Allownulls

Id int No

Name varchar(50) Yes

Dateofbirth date yes

Gender varchar(50) Yes

Deprtmentid varchar(50) Yes


My function:
SQL
USE [sdb]
GO
/****** Object:  UserDefinedFunction [dbo].[getempbygender]    Script Date: 09/02/2016 19:41:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[getempbygender](@Gender varchar(50))
returns table
as
return( select Id,Name,Dateofbirth,Deprtmentid from emp where Gender=@Gender ).


whenever excute 'Command(s) completed successfully' msg will be given but while call the function error will thrown like as "Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.getempbygender" could not be bound."



call the function
:

SQL
select [dbo].[getempbygender] 'Male'


pls help me.

Thank u

What I have tried:

whenever excute 'Command(s) completed successfully' msg will be given but while call the function error will thrown like as "Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.getempbygender" could not be bound."

Posted
Updated 2-Sep-16 5:12am

1 solution

Your call to your function is wrong. It should be select * from [dbo].[getempbygender]('Male')

Updated with correction from Richard.
 
Share this answer
 
v3
Comments
Richard Deeming 2-Sep-16 12:03pm    
Almost. It's a table-valued function, so it should be:
SELECT * FROM dbo.getempbygender('Male')
AnvilRanger 2-Sep-16 13:37pm    
+5
Richard Deeming 2-Sep-16 13:39pm    
You missed the FROM in the update. :)
AnvilRanger 2-Sep-16 14:07pm    
That is what I get for posting during a 4 hour project update meeting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900