[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

Convert smalldate to character string on select statement

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
Aleks
Asked:
Aleks
  • 2
1 Solution
 
SQL_SERVER_DBACommented:
CONVERT(NVARCHAR, column name, 101)
0
 
elimesikaCommented:
use

b.Processtep +  'date started: ' + CONVERT ( nvarchar(10), a.LastModified ,101)
0
 
AleksAuthor Commented:
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
 
elimesikaCommented:
use

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

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now