Solved

Convert smalldate to character string on select statement

Posted on 2008-06-19
4
655 Views
Last Modified: 2012-06-21
I have the following sql Select statement

SELECT a.ActivityId, a.CaseId, a.FirmId, a.ActType, a.ActDesc, a.DateInitiated, a.LastModified,
a.ProcesstepID,a.dateinitiated,b.Processtep + '/' + 'date started: ' + a.LastModified as Step
, b.pstepdescription,b.Ordernum,b.Timeframe,b.Emailalert

a.Lastmodified is a smalldate type, a.processtep is an nvarchar

I want to display the result of both in a single column and convert the date to nvarchar in the format of mm/dd/yyyy.  How can I do this ?

The error i get right now is below.

Conversion failed when converting character string to smalldatetime data type.
0
Comment
Question by:amucinobluedot
[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
  • 2
4 Comments
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 21823763
CONVERT(NVARCHAR, column name, 101)
0
 
LVL 19

Expert Comment

by:elimesika
ID: 21823819
use

b.Processtep +  'date started: ' + CONVERT ( nvarchar(10), a.LastModified ,101)
0
 

Author Comment

by:amucinobluedot
ID: 21824470
I ran the query as:

SELECT b.Processtep
+ ' / ' + 'date started: ' + CONVERT ( nvarchar(10), a.LastModified ,101)
+ ' / ' + 'target date: ' + CONVERT ( nvarchar(10), a.Schdemailon ,101)
+ ' / ' + 'comments: ' + a.ActDesc as Step
FROM dbo.Activities  a

so far it worked, but the problem is that if the 'date started' is null the result is not displayed, it displays "NULL" as result.  How can I display the date if not null or just ' ' if the date is null.

Thanks,
0
 
LVL 19

Accepted Solution

by:
elimesika earned 500 total points
ID: 21824498
use

ISNULL(CONVERT ( nvarchar(10), a.LastModified ,101), '')
ISNULL(CONVERT ( nvarchar(10), a.LastModified ,101), '')

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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