Know a value 'jjfda', how to find it in that table, that field

xiaoxiao2021-03-06  61

Take Pubs as an example, I now know a value, 'JJFDA', but I don't know which field he is in?

Can you realize the query?

-------------------------------------------------- -------------

--test

Declare @str varchar (100)

Set @ Str = 'White' - String to Search

Declare @s varchar (8000)

Declare TB CURSOR LOCAL FOR

Select s = 'if exists (SELECT 1 from [' B.Name '] where [' a.name '] Like' '%' @ STR '%' ')

PRINT '' The table and field: [' b.Name ']. [' a.name '] '' '

From syscolumns a join sysobjects b on A.Id = B.ID

WHERE B.XTYPE = 'u' and a.status> = 0

And A.XUSERTYPE IN (175, 239, 231, 167)

Open TB

Fetch next from tb @S

While @@ fetch_status = 0

Begin

EXEC (@S)

Fetch next from tb @S

end

Close TB

DEAALLOCATE TB

/*--Test Results

The tables and fields: [Authors]. [Au_lname]

- * /

转载请注明原文地址:https://www.9cbs.com/read-90821.html

New Post(0)