SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Datetime convert
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Muhrab
Starting Member

Russia
3 Posts

Posted - 05/07/2012 :  07:11:56  Show Profile  Reply with Quote
Hello, can you give me a good tip plz
I need to convert a field in a Table from datatime (2001-07-01 00:00:00.000) to int (20010701)i need to update with this a column in a table.
Thx

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 05/07/2012 :  07:24:11  Show Profile  Reply with Quote
What is the data type of your column? You can find that out by running this query:
SELECT DATA_TYPE FROM INFORMATION_SCHEMA.[COLUMNS] 
WHERE TABLE_NAME = 'YourTableName' AND COLUMN_NAME = 'YourColumnName'
If it is DATE, DATETIME, DATETIME2, or SMALLDATETIME you are doing the right thing - don't do any changes to the table or the way the column is stored.

If you want to query the table and get the result in the "20010701" format, do it like this:
SELECT CONVERT(CHAR(8),YourColumn,112);
However, it would be better for a variety of reasons to not do this conversion in SQL - instead, simply query the column, send the result to the client (such as a presentation layer) and have the client do the necessary conversion.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000