converting date data type into varchar
Posted
by
Sheetal Inani
on Stack Overflow
See other posts from Stack Overflow
or by Sheetal Inani
Published on 2011-01-03T06:18:24Z
Indexed on
2011/01/03
6:53 UTC
Read the original article
Hit count: 212
sql
|sql-server-2005
I have some dates fields in table. These columns contain dates in the following format:
mmddyy
For example:
31/12/2010 00:00:00:0000
I need to import these values into a table which is set to varchar and numeric and formats dates like this:
monthName varchar
Year numeric(4,0)
currently I'm using
INSERT INTO [School].[dbo].[TeacherAttendenceDet]
([TeacherCode],
[MonthName],
[Year])
(SELECT MAX(employeecode),
Datename(MONTH, dateofjoining) AS MONTH,
Datepart(YEAR, dateofjoining) AS DATE
FROM employeedet
GROUP BY dateofjoining)
but datename()
gives result in date format.. I have to save it in varchar
format
How can I do this? this is employeemast table:
EmployeeCode numeric(5, 0)
PayScaleCode numeric(7, 0)
DesignationCode varchar(50)
CityCode numeric(5, 0)
EmployeeName varchar(50)
FatherName varchar(50)
BirthDate varchar(50)
DateOfJoining varchar(50)
Address varchar(150)
this is TeacherAttendenceDet table
TeacherCode numeric(5, 0) Unchecked
Year numeric(4, 0) Unchecked
MonthName varchar(12) Unchecked
i have to insert in teacherattendencedet table the monthname and year from employeemast
© Stack Overflow or respective owner