2010-01-26 20 views
5

Comment concaténer deux colonnes dans un serveur sql d'instruction select 2005?Concat deux colonnes dans un serveur sql d'instruction select 2005

Voici ma déclaration Select FirstName,secondName from Table ...

Maintenant, j'ai essayé concating secondName avec FirstName en utilisant

Select FirstName + ' ' + secondName from Table 

Mais certaines valeurs sont NULL dans la colonne secondName pour certains enregistrements .. Mon instruction select retourne NULL au lieu de FirstName .. Je veux avoir FirstName si secondName est NULL ..

Répondre

12

SELECT FirstName + ISNULL(' ' + SecondName, '') from Table

+1

@roufamatic ISNULL funtion m'a aidé ... –

0

Si l'un de vos champs est numérique, vous pouvez lancer à un string comme suit:

SELECT FirstName + ISNULL(' ' + SecondName, '') + ' age(' + CONVERT(nvarchar,age) + ')' from Table