Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Update Date Column

Author  Topic 

Sonu619
Posting Yak Master

202 Posts

Posted - 2012-07-20 : 02:25:47
Hi guys,

I have column Sale_date and below is sample data

Sale_Date
05/22/2011
06/15/2010
09/22/2011

How i can update Sale_Date Column so End result would be

Sale_Date
5/22/11
6/15/10
9/22/11

Thanks For help..

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-20 : 02:40:58
The data type of that column is what?
Do you need that format for display purpose?
Can you do that in your front end?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sonu619
Posting Yak Master

202 Posts

Posted - 2012-07-20 : 11:03:56
Data Type for Column is Varchar. I am trying to automate Report in SSRS so user can select what kinda report they want and print by self and they want to see this kinda format.I tried to fix through SSRS Expression but no luck so i am thinking to update after upload table update date field.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-20 : 11:12:08
quote:
Originally posted by Sonu619

Data Type for Column is Varchar. I am trying to automate Report in SSRS so user can select what kinda report they want and print by self and they want to see this kinda format.I tried to fix through SSRS Expression but no luck so i am thinking to update after upload table update date field.


whats the basic datatype of field is it varchar or datetime?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-07-20 : 11:47:48
Even though this is probalby realy bad thung to do, here is some code that'll get you close. It will pad a leading zero to single digit months. So, if you need to remove that you'll have to add a little more code to remove that.
DECLARE @Foo TABLE(Val VARCHAR(20))

INSERT @Foo
VALUES
('05/22/2011'),
('06/15/2010'),
('09/22/2011')


UPDATE @Foo
SET Val = CONVERT(VARCHAR(8), CONVERT(DATETIME, Val, 101), 1)

SELECT *
FROM @Foo
EDIT: cut-n-past error.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-20 : 14:13:08
quote:
Originally posted by Sonu619

Data Type for Column is Varchar. I am trying to automate Report in SSRS so user can select what kinda report they want and print by self and they want to see this kinda format.I tried to fix through SSRS Expression but no luck so i am thinking to update after upload table update date field.


what SSRS expression you were using? did you try FormatDatetime() function

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-20 : 14:13:08
quote:
Originally posted by Sonu619

Data Type for Column is Varchar. I am trying to automate Report in SSRS so user can select what kinda report they want and print by self and they want to see this kinda format.I tried to fix through SSRS Expression but no luck so i am thinking to update after upload table update date field.


what SSRS expression you were using? did you try FormatDatetime() function

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sonu619
Posting Yak Master

202 Posts

Posted - 2012-07-21 : 00:50:11
My source file date, datatype if varchar....
Go to Top of Page
   

- Advertisement -