Wednesday, May 9, 2007

Selecting concatanation fo two columns in SQL

Okie...if you want to select firstname + lastname as fullName its eazy ...and anyone can do it...

But, what when you want to select three numbers concatanated...namely, month, date and year...

try using "+" and the SQL server gives you the sum of the three numbers which is no good...

Here is a tiny trick i played on SQL server...

SELECT (Upper(MONTH)) + '/'+Upper(Day)+'/' +Upper(Year) as Date FROM DateTable...

when the SQL server does toUpper function, it assumes, the argument is a string and volah..the query runs seemlessly

Have fun coding...

No comments: