?
Solved

Convert smalldate to character string on select statement

Posted on 2008-06-19
4
Medium Priority
?
666 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 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