Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I add the table name in the Select

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I need to show the table name for troublshooting in a lot of Selects on different Tables.
Is there a was to get it without having to hard code it in like I it did below. It does not work anyway.
Part of the issue is I need to do a group by.
Code:
Select 'Tablename', manager, ResourceLastName, ResourceFirstName
from SOWTimeReporting
Where ResourceLastName = @lastname
Group by 'Tablename', manager,ResourceLastName, ResourceFirstName

like ????
Select TABLE SCHEMA THINGY HERE, manager, ResourceLastName, ResourceFirstName
from SOWTimeReporting
Where ResourceLastName = @lastname
Group by TABLE SCHEMA THINGY HERE, manager,ResourceLastName, ResourceFirstName

DougP
 
It's easy enough to add the literal string with the table name in it, but it's a whole different ball game for WHY you need it, and how it helps troubleshooting.
Whatever is running the select or procedure should be aware that it has had a problem.

You're hardcoding the FROM <TableName>, so just add the hardcoded SELECT <TableName> TableName
If you're dynamically generating the select and then executing it, then add it in in-line as well.

Lodlaiden

You've got questions and source code. We want both!
There's a whole lot of Irish in that one.
 
Sorry, I am a little confused. is SOWTimeReporting the db or the table name? Could you give us the db structure, dbname, tables and fields so we can see what it is you are actually trying to do? Are you wanting to cycle thru each table and pull this information without having to modify the query for each table?

wb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top