Posts

Showing posts from 2009

SQL Server 2005 Query

EOY- End Of Year.. Happy New Year Everyone !!! Well I had to update a Column End_Date to a particular value '12/31/2010' since it is the EOY. Instead of viewing each table and editing all the columns, I thought of writing a SQL Query to update all the End_Date to '12/31/2010' in all the tables. SysObjects - It has the list of all tables present in the database. SysColumns Table- It has the list of all the columns in all the tables in the database. SysObjects and SysColumns are linked by "id" . So here is the query to display all the table names based on the column end_dt. SELECT SYSOBJECTS.NAME FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSCOLUMNS.ID = SYSOBJECTS.ID WHERE SYSCOLUMNS.NAME='END_DT' ; Then I had to loop through each table using cursors and use the update statement to change the end_dt values. Full Query : SET QUOTED_IDENTIFIER ON DECLARE @TableName varchar(100) DECLARE @SQL VARCHAR(100) DECLARE @getTableName CURSOR SET @getTableName= CURSOR...

DateTime.Now in C#

DateTime Class is used to get the various possibilities that can be included within a day, month or a year. I am going to discuss about some functionalities of DateTime.Now here. For example: To get the current date and time, use DateTime.Now which gives us 6/24/2009 9:45:00 AM DateTime.Now has 5 important functions to get date and time in different formats. 1) DateTime.Now.ToLongDateString() - Displays in the format "Wednesday, June 24, 2009." 2) DateTime.Now.ToLongTimeString() - Displays in the format "12:00:00 AM. " 3) DateTime.Now.ToShortDateString() - Displays in the format "6/24/2009" 4) DateTime.Now.ToShortTimeString() - Displays in the format "12:00 AM" 5) DateTime.Now.ToString("Format") - This method accepts different formats. The formats can be obtained from GetDateTimeFormats() method of DateTime.Now and has 133 different formats that anyone can think of while displaying Date and Time. For example: DateTime.Now.ToString(...