Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Select All and change the format of one column

I was wondering. If I have a table with 20(or more) column names in and I want to select All of them, but one column of those 20 columns is a date column and you would like to change the format of that column, how would you do that? This obviously didn't work (created duplicate columns)

Select *, CONVERT(varchar(100),courseStartDate,111) from EthicsManagement

This is to avoid writing a select statement selecting ALL 20 columns individually and converting one of them with the statement

  Select xxxx,xxx,xxx,xxx,xx,xx,xxx,xxx,xx,xx,xxx,xxx,xx, CONVERT(varchar(100),courseStartDate,111) from xxx
like image 481
Ruan Avatar asked Apr 15 '13 12:04

Ruan


People also ask

How do I format a column in SQL?

The SQL*Plus COLUMN command is used to change the appearance of the data returned for a given column using the following syntax: COLUMN column_name option1 option2 ... Once set, the SQL*PLUS COLUMN command will format any column of the specified name until it is unset with the CLEAR COLUMNS command.


1 Answers

It should let you do that, as long as you name the column something different:

Select *, CONVERT(varchar(100),courseStartDate,111) as myConvertedDateColumn
from EthicsManagement
like image 112
Aaron Avatar answered Sep 24 '22 16:09

Aaron