Solved

Convert smalldate to character string on select statement

Posted on 2008-06-19
4
650 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now