OnlyHope OnlyHope - 4 years ago 146
SQL Question

Table Name Display

Is there a function to show the table name at sql server?
I want to check if the user is found at a specific table, the table's name should be returned, can I do it?

IF EXISTS(
SELECT Std_ID
FROM Student
WHERE Std_ID = @UserId)


I want it here to return Student.

Answer Source

Since you already know you're going to check the Student table, just return the value 'Student'

if(exists(select * from Student where Std_ID = @UserId))
begin
  select 'Student' as TableName
  return;
end
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download