Solved

Update field to date format mmm yy

Posted on 2002-06-25
5
611 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
ID: 7108081
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
ID: 7108089
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
ID: 7108097
set MailStatus = right(convert(varchar(9),getdate(),13),6)
0
 

Expert Comment

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

Author Comment

by:naqayya
ID: 7109901
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to share SSIS Package? 6 37
T-SQL: Do I need CLUSTERED here? 13 45
what are the unique tables in SQL master database 5 62
SQL View nearest date 5 37
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 …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

803 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