Student
Student

Reputation: 91

The multi-part identifier "dbo.showSelectedTable" could not be bound

I have trying to make function to call a table that selected by user I'm try to make it and finish it

CREATE FUNCTION showSelectedTable(@code varchar(1)) RETURNS 
@tempEMP TABLE
(id nvarchar(9),name nvarchar(20),mdname nvarchar(20),lname nvarchar(50),   tgl datetime,adrs nvarchar(50),sex nvarchar(1),salary int,superssn nvarchar(9),dno nvarchar(3))

BEGIN

DECLARE @temp1 TABLE (id nvarchar(9),name nvarchar(30),idmgr nvarchar(9),dtime datetime)
DECLARE @temp2 TABLE (EmpName nvarchar(30),ProjectName nvarchar(30))

    if @code = 'E'
        BEGIN
        INSERT INTO @tempEMP
            SELECT *
            FROM employee
        RETURN;
        END
    ELSE IF @code = 'D'
        BEGIN           
            INSERT INTO @temp1
                SELECT *
                FROM department
            RETURN;
        END
    ELSE IF @code = 'W'
        BEGIN
            INSERT INTO @temp2
                SELECT e.fname,p.pname
                FROM works_on W,employee E,project P
                WHERE E.ssn = W.ssn AND W.pno = P.pnumber
            RETURN;
        END
    RETURN;
END

but when try to call,

select dbo.showSelectedTable 'W'

I got this message:

The multi-part identifier "dbo.showSelectedTable" could not be bound.

Anybody can help me to solve this?

Upvotes: 2

Views: 977

Answers (1)

Abdul Rasheed
Abdul Rasheed

Reputation: 6709

Use this,

select * from dbo.showSelectedTable('W')

It is a Table-Valued Functions, treat the table-valued function just as you would a table.

Upvotes: 5

Related Questions