473,395 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

String/Date Concatenation causes conversion error - streamline fix suggestions

Hi,
I'm trying to concatenate a Description (nchar(100)) and Date
(datetime) as Description and my initial effort was just
"...description+' '+open_date as description..." which throws a date/
string conversion error; finally came up with a working string below
but don't think it's the optimal way to do this - any suggestions?

select (rtrim(description)+'
'+rtrim(convert(char(2),datepart(mm,open_date)))
+'/'+convert(char(2),datepart(dd,open_date))
+'/'+convert(char(4),datepart(yyyy,open_date))) as description from
oncd_opportunity where opportunity_id=?

open_date is not a required field at the db level, but it is required
on the form so it should not be null as a rule.

Sep 4 '07 #1
2 8631
You can use the third optional parameter of the convert to get the
date in the format you want.

convert(char(20),open_date,101)

-
Shiju

On Sep 4, 7:34 pm, Chris H <chollst...@broadreachpartnersinc.com>
wrote:
Hi,
I'm trying to concatenate a Description (nchar(100)) and Date
(datetime) as Description and my initial effort was just
"...description+' '+open_date as description..." which throws a date/
string conversion error; finally came up with a working string below
but don't think it's the optimal way to do this - any suggestions?

select (rtrim(description)+'
'+rtrim(convert(char(2),datepart(mm,open_date)))
+'/'+convert(char(2),datepart(dd,open_date))
+'/'+convert(char(4),datepart(yyyy,open_date))) as description from
oncd_opportunity where opportunity_id=?

open_date is not a required field at the db level, but it is required
on the form so it should not be null as a rule.

Sep 4 '07 #2
Shiju,

Thanks - the working (and streamlined) query becomes:

select (rtrim(description)+' '+convert(char(20),open_date,101)) as
description from oncd_opportunity where opportunity_id=?

Much more elegant - thanks!

Sep 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
13
by: Don | last post by:
Hi, I have an SQL string that I'm trying to code into VBA and it's giving me trouble. I tried to use line continuation and concatenation as best I can to make it work. However, I'm stuck. I know...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
2
by: RN1 | last post by:
A TextBox displays the current date (in dd/mm/yyyy format) & time when a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the date into international format so that the remote server...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.