sql server - Select Date query in SQL -


i have date column want write "s" when there sunday if have data this

datecolumn   1-1-2017 2-1-2017     3-1-2017     4-1-2017     5-1-2017     6-1-2017     7-1-2017     8-1-2017     9-1-2017     10-1-2017     11-1-2017     12-1-2017     13-1-2017 

in if on date there sunday day how write "sun" instead on date this

select datecolumn table1   datecolumn   1-1-2017     2-1-2017     3-1-2017     sun     5-1-2017    6-1-2017     7-1-2017     8-1-2017     9-1-2017     10-1-2017     sun     12-1-2017    13-1-017 

try this:

select case when datepart(dw, datecolumn) = 1 'sun' else cast(datecolumn nvarchar(max)) end datecolumn table1 

hope helps.

ps - might have modify cast(datecolumn nvarchar(max)) convert if need dates in specific date format.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -