Solved

Convert smalldate to character string on select statement

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query 34 98
Access 2010 Query Syntax 5 30
convert in derived column 7 27
performance query 4 20
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
'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 …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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