Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Oct 4, 2000

Year 2000 Checks

By Alan Enderby

Want to know where dates are used in your database ?

This script
1) Displays all tables containing columns with a datatype of datetime
or smalldatetime
2) Displays all tables containing columns with a column name
containing (Year, month day...)
3) Shows stored procedures containing Year, month day or any of the
date functions (datediff,dateadd ....)
4) It can be modified to search for your own date user types


SET NOCOUNT ON

declare @msg varchar(255)
Select @msg='Days until Jan 1st 2000 = ' +
convert(varchar(5),Datediff(dd,getdate(),'1 jan 2000'))
print @msg
select @msg=replicate('=',datalength(@msg))
print @msg
print ' '



drop table #t1
go

create table #t1 (search_string varchar(255))
Insert into #t1 values ('%[ ]date%')
Insert into #t1 values ('%day%')
Insert into #t1 values ('%Month%')
Insert into #t1 values ('%Year%')
Insert into #t1 values ('%Week%')
Insert into #t1 values ('%dateadd%')
Insert into #t1 values ('%datediff%')
Insert into #t1 values ('%datepart%')
Insert into #t1 values ('%getdate()%')

-- Show tables with columns or names containing date references

select distinct 'Table'=o.name , 'Column'= c.name , 'Format'=
t.name
from sysobjects o , syscolumns c , systypes t ,#t1 m
Where o.id=c.id
and o.type='U'
and c.type=t.type
and (t.name like '%date%'
or patindex(search_string,c.name) > 0)
order by o.name,c.name

print ' '

-- Show stored procedures containing date related words

select search_string=substring(search_string,1,20),
'SP Name'=upper(o.name),
Seq=colid ,
'SP Line'=substring(text,patindex(search_string,text)-5, 30)
from syscomments c , sysobjects o , #t1 t
where o.id=c.id
and patindex(search_string,text) > 0
order by substring(search_string,1,20),name
go



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM