无法绑定多部分标识符“dbo.showSelectedTable”

时间:2022-08-07 09:21:58

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.

无法绑定多部分标识符“dbo.showSelectedTable”。

Anybody can help me to solve this?

有人可以帮我解决这个问题吗?

1 个解决方案

#1


5  

Use this,

用这个,

select * from dbo.showSelectedTable('W')

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

它是一个表值函数,就像处理表一样处理表值函数。

#1


5  

Use this,

用这个,

select * from dbo.showSelectedTable('W')

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

它是一个表值函数,就像处理表一样处理表值函数。