select c.*
from syscolumns c join sysobjects o on o.id=c.id and o.name = 'orders'
returns
Id
Customer
Product
03-28-2011
04-04-2011
04-11-2011
04-18-2011
This is correct. But I want only the columns that match the pattern 99-99-9999. So I tried this where cast(o.name as varchar) like '%-%-%' which didn’t return any results. Then I tried this: where cast(o.name as varchar) like 'P%' (I expected to get “Product”) and it also did not return anything. Why??? What syntax should I use to get the columns that are “dates” ?
Thanks!
For each part of your question…
Date pattern matching
You can use [0-9] to specify ranges.
So for
99-99-9999you’d haveFor dates, you can use ISDATE too or things like this to restrict further
Column filters
These conditions can never all be true because they are all on
o.nameand
The latter 2 should be on
c.namein your queryFinally
Use the newer sys.columns and sys.objects. Or INFORMATION_SCHEMA.COLUMNS which is probably best here