Solved

Update field to date format mmm yy

Posted on 2002-06-25
5
619 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

809 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