When I run the below code it runs successfully. drop function udffullname go cre
ID: 3728920 • Letter: W
Question
When I run the below code it runs successfully. drop function udffullname go create function dbo.udffullname(@studentid int) returns int as begin return (select concat(lastname, ',',firstname) as Lastandfirst from student) end but when i got to test it I get the below error message. Can you let me know why? I am not sure what is wrong with my code that it will not select my attributes from my code. select studentid,firstname,lastname, [dbo].[udffullname].[studentid] from student join dbo.udffullname(12) as functionfullname on student.studentid = dbo.functionfullname.studentid; Msg 208, Level 16, State 3, Line 16 Invalid object name 'dbo.udffullname'.
Explanation / Answer
You need to remove the schema name "dbo" while defining your function udffullname.
So the correct function definition would be:
create function udffullname(@studentid int)
returns int as
begin
return (select concat(lastname, ',',firstname) as Lastandfirst from student)
end
And the select query would be:
select studentid, firstname, lastname from
student join dbo.udffullname(12) as functionfullname
on student.studentid = functionfullname.studentid;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.