Hello
I am using SQL server 2008 R2. I have a query where I have dates in different columns pulled from my database among other things. The client is requiring that the date be formatted as mmddyyyy. The database returns the date value as varchar (8) and formatted as yyyymmdd. I have tried several things to get this to be converted but haven't had any luck. My query is as follows. If someone could let me know the best way to do this it would be very helpful.
select appointments.last_name as 'patient last name', appointments.first_name as 'patient first name', appointments.address_line_1, appointments.address_line_2, appointments.city,
appointments.state, appointments.zip, appointments.home_phone, appointments.appt_nbr, appointments.appt_date, person.date_of_birth,
person.sex, patient.med_rec_nbr, provider_mstr.national_provider_id, provider_mstr.first_name, provider_mstr.last_name, specialty_mstr.description,
appointments.location_id, location_mstr.location_name, person.email_address
into #TESTFILE
from ngprod.dbo.appointments
inner join ngprod.dbo.person
ON appointments.person_id=person.person_id
inner join ngprod.dbo.patient
ON appointments.person_id=patient.person_id
inner join ngprod.dbo.provider_mstr
ON appointments.rendering_provider_id=provider_mstr.p rovider_id
inner join ngprod.dbo.specialty_mstr
ON provider_mstr.specialty_code_1=specialty_mstr.spec ialty_code
inner join ngprod.dbo.location_mstr
ON appointments.location_id=location_mstr.location_id
where appointments.appt_date ='20130624'
update #TESTFILE
set last_name=(last_name+ ' MD')
alter table #TESTFILE
add Ending nvarchar (70) not null default ('$')
--Select CONVERT(nvarchar(8), getdate(),107) as [Date in mmddyyy Format]
--SELECT convert(varchar (8),appointments.appt_date,'mmddyyyy')
--select convert(char(8),appt_date,117) from #pressganey
--alter table #TESTFILE
--alter column appt_date date
--REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY]
--SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS ----[MMDDYYYY]
select * from #TESTFILE
order by last_name
I am using SQL server 2008 R2. I have a query where I have dates in different columns pulled from my database among other things. The client is requiring that the date be formatted as mmddyyyy. The database returns the date value as varchar (8) and formatted as yyyymmdd. I have tried several things to get this to be converted but haven't had any luck. My query is as follows. If someone could let me know the best way to do this it would be very helpful.
select appointments.last_name as 'patient last name', appointments.first_name as 'patient first name', appointments.address_line_1, appointments.address_line_2, appointments.city,
appointments.state, appointments.zip, appointments.home_phone, appointments.appt_nbr, appointments.appt_date, person.date_of_birth,
person.sex, patient.med_rec_nbr, provider_mstr.national_provider_id, provider_mstr.first_name, provider_mstr.last_name, specialty_mstr.description,
appointments.location_id, location_mstr.location_name, person.email_address
into #TESTFILE
from ngprod.dbo.appointments
inner join ngprod.dbo.person
ON appointments.person_id=person.person_id
inner join ngprod.dbo.patient
ON appointments.person_id=patient.person_id
inner join ngprod.dbo.provider_mstr
ON appointments.rendering_provider_id=provider_mstr.p rovider_id
inner join ngprod.dbo.specialty_mstr
ON provider_mstr.specialty_code_1=specialty_mstr.spec ialty_code
inner join ngprod.dbo.location_mstr
ON appointments.location_id=location_mstr.location_id
where appointments.appt_date ='20130624'
update #TESTFILE
set last_name=(last_name+ ' MD')
alter table #TESTFILE
add Ending nvarchar (70) not null default ('$')
--Select CONVERT(nvarchar(8), getdate(),107) as [Date in mmddyyy Format]
--SELECT convert(varchar (8),appointments.appt_date,'mmddyyyy')
--select convert(char(8),appt_date,117) from #pressganey
--alter table #TESTFILE
--alter column appt_date date
--REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY]
--SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS ----[MMDDYYYY]
select * from #TESTFILE
order by last_name