1

I have a list of market data tables in one of our environments and need to search every column in the list for a certain string. Can anyone point me in the right direction.

1> select @@version
2> go

Adaptive Server Enterprise/15.0.3/EBF 16558 ESD#1/P/Solaris AMD64/OS 5.10/

Thanks

3
  • Are you looking to search for column names, or the content of the columns?
    – Hannah Vernon
    Oct 14, 2015 at 15:32
  • 1
    @MichaelO Your Sybase version is out of support. Please look into a possiblity of upgrading it to atleast Sybase 15.7 or 16.0 with latest Service Pack (EBF is not used anymore, Sybase now uses Service Pack)
    – Kin Shah
    Oct 16, 2015 at 14:29
  • gallery.technet.microsoft.com/scriptcenter/… has code for Microsoft SQL Server. If you do not find a better answer, perhaps the code will help you work out a solution for your version of SyBase.
    – RLF
    Oct 16, 2015 at 15:04

1 Answer 1

0

You can query syscolumns and sysobjects in each database to get the information you need.

select 
  distinct so.name as TABLE_NAME,
  sc.name as COLUMN_NAME
from 
  syscolumns sc,
  sysobjects so
where 
  sc.id = so.id
and   sc.name like '%searchstring%'
order by so.name

If you need to limit your search to specific tables, then you can add an additional 'and' clause:

and so.name in ("Table1","Table2","Table3")
4
  • In Sybase does master contain the details on all syscolumns and sysobjects in the server? That seems to be what your first sentence is describing. Or does each database keep its own syscolumns and sysobjects data?
    – RLF
    Oct 14, 2015 at 13:06
  • @MichaelGardner The OP wants to search for a particular string in all the columns. Your answer searches for columns in tables. Please refer to my comment above, since this question is a dupe of the one that I referenced.
    – Kin Shah
    Oct 16, 2015 at 14:25
  • @MichaelGardner Its clear from the question - need to search every column in the list for a certain string --> So the OP is asking to search every column in the list for a particular string. Also, your query has syntax error. Did you try running it in sybase 15.0.3 instance ? It should be SELECT so.name, sc.name as column_name FROM sysobjects so INNER JOIN syscolumns sc ON so.id = sc.id where so.type = 'U' and lower(sc.name) like '%test%'
    – Kin Shah
    Oct 16, 2015 at 15:03
  • @kin Thanks for the correction, I was producing this from memory. As for the OPs intention, I was not the only person to see ambiguity in the question, so I will continue to defer to the OP to clarify when he sees fit. Oct 16, 2015 at 16:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.