Solved

Update field to date format mmm yy

Posted on 2002-06-25
5
596 Views
Last Modified: 2009-12-16
I use the following code in an sp:

----------------------------------------------------------
CREATE PROCEDURE sp_ReturnMailProcessing

@myDonorID int
AS

update tblDonors
set MailStatus = 'Jun 02'
where DonorID = @myDonorID and (MailStatus = 'Yes' or MailStatus = 'YES')
GO
----------------------------------------------------------

I want to set the MailStatus to a text value of the current date in the format mmm yy. MailStatus is of type varchar.

Can you show me the code please? Thanks.
0
Comment
Question by:naqayya
5 Comments
 
LVL 6

Expert Comment

by:curtis591
Comment Utility
I am not sure how your table is setup but if it a datetime format of sometype you save the data in the with day inside of it and when you want to display the data you do something like to remove the day. Or you could turn your field type into a character to save it but you won't be able to date queries with it then.
select convert(char(4),getdate(),107) + right(datename(yy,getdate()),2)
0
 
LVL 6

Expert Comment

by:curtis591
Comment Utility
you could also use the year function

select convert(char(4),getdate(),0) + right(year(getdate()),2)
0
 
LVL 18

Accepted Solution

by:
nigelrivett earned 50 total points
Comment Utility
set MailStatus = right(convert(varchar(9),getdate(),13),6)
0
 

Expert Comment

by:woregul
Comment Utility
set MailStatus = substring(datename(m, getdate()), 1, 3) + ' ' + convert(varchar, datepart(yy, getdate()))
0
 

Author Comment

by:naqayya
Comment Utility
I think nigelrivett's solution is the simplest - but it needed a slight modification:

set MailStatus = right(convert(varchar(9),getdate(),6),6)

The date style 13 or 113 will always return century(yyyy). However 6 works fine.

Thanks all.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now