PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > String/Date Concatenation causes conversion error - streamline fix suggestions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
String/Date Concatenation causes conversion error - streamline fix suggestions

Réponse
 
LinkBack Outils de la discussion
Vieux 04/09/2007, 15h34   #1
Chris H
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

  Réponse avec citation
Vieux 04/09/2007, 18h13   #2
Shiju Samuel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: String/Date Concatenation causes conversion error - streamline fix suggestions

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.



  Réponse avec citation
Vieux 04/09/2007, 20h04   #3
Chris H
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: String/Date Concatenation causes conversion error - streamline fix suggestions

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!

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h46.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08052 seconds with 11 queries