Solved

Update field to date format mmm yy

Posted on 2002-06-25
5
623 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS GUID Variable 2 37
SQL Distinct Question 3 15
SQL Server Compression Decision 5 48
Please explain Equi-join 3 16
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

730 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