|
I need to create a query to first get all the tables with a particular column ( column name is log ) and, once I have this list of tables, iterate over each table to see if the log column contains a specific piece of text. So far I have this: If I do a select * from mytemp, I get the 5 tables I'm looking for. I need to write some kind of loop to iterate over these 5 tables, do a select log from thistable where log like '%hack%'. I'm close ( at least I'd like to think so ), but I need the rest of this query. I hope someone can help me. Thanks.
(comments are locked)
|
|
Hello kathy, You can use dynamic sql +1 use a cursor to iterate and create the dynamic SQL. Also keep in mind that like %somevalue% causes SQL to ignore indexes.
Aug 12 '10 at 10:43 PM
Håkan Winther
Hakan winther, i agree with you, If your filter is like 'SomValue%' then optimizer will not ignore the indexes.
Aug 12 '10 at 10:56 PM
Cyborg
It's giving me an error: Msg 207, Level 16, State 1, Line 1 Invalid column name 'ID'. This is against sql server 2008.
Aug 13 '10 at 04:53 AM
KathyTheGreat
sorry its my fault since i worked with a sample table, replace that id with 'Log'
Aug 13 '10 at 05:00 AM
Cyborg
Cyborg - thank you, thank you. It worked great. I so appreciate your help.
Aug 13 '10 at 05:03 AM
KathyTheGreat
(comments are locked)
|

