September 10, 2013 at 3:56 am
How to know a Table name by a value?
plz help me
September 10, 2013 at 4:28 am
karunakar2351 (9/10/2013)
How to know a Table name by a value?plz help me
Please explain in a little more detail what you mean, this is far too vague to answer.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 10, 2013 at 4:35 am
Ok
'RO04381',
'RO04052',
'RO04210'
The above three values are placed in my database but i dont know the column name and Table name but i need to track these 3 values
September 10, 2013 at 5:12 am
Run this to generate your scripts:
DECLARE @MySearchCriteria VARCHAR(500)
SET @MySearchCriteria = '''RO04381'',''RO04052'',''RO04210'''
SELECT 'SELECT ' + c.columnlist + ' FROM ' + t.name + ' WHERE ' + w.whereclause
FROM sys.tables t
CROSS APPLY (
SELECT STUFF((
SELECT ', ' + c.Name AS [text()]
FROM sys.columns c
WHERE t.object_id = c.object_id
AND c.collation_name IS NOT NULL
AND c.max_length > 6
FOR XML PATH('')
), 1, 2, '' )
) c (columnlist)
CROSS APPLY (
SELECT STUFF((
SELECT ' OR ' + c.Name + ' IN (' + @MySearchCriteria + ')' AS [text()]
FROM sys.columns c
WHERE t.object_id = c.object_id
AND c.collation_name IS NOT NULL
AND c.max_length > 6
FOR XML PATH('')
), 1, 4, '' )
) w (whereclause)
ORDER BY t.name
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply