Sql concatenate select query statement

The following example concatenates non character, non binary expressions by using “CAST”.

EmpData having following data :

Id   Name    DateTime                                          Address

2    Madhu    2011-02-02 00:00:00.000    Pune
select ‘ this is my ‘ + name +’–‘ + CAST( Id as nvarchar) from EmpData

output will be –

this is my Madhu–2

Using “CONVERT” –

select ‘ this is my ‘ + name +’–‘ + CONVERT(nvarchar,TimeSpan,106 ) from EmpData

output will be –

this is my Madhu–02 Feb 2011

for more info link :

http://msdn.microsoft.com/en-us/library/ms187928.aspx

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s