Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Concatenate 2 int colums

Author  Topic 

jmersing
Yak Posting Veteran

57 Posts

Posted - 2011-06-06 : 08:01:52

I have a date and time column that I would like to concatenate. I tried a few variations but nothing seems to work.

CAST(TRLogTime AS int) + '-' + TRLogDate AS Expr1

TRLogTime + '-' + TRLogDate AS Expr1

I would like to add an underscore between the vales as well.

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-06-06 : 08:03:27
try casting as VARCHAR

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

jmersing
Yak Posting Veteran

57 Posts

Posted - 2011-06-06 : 08:17:47
I changed it to Varchar and got a weird result in the Concat column?

Time Date Concat
64229 20110606 20174835
64229 20110606 20174835
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2011-06-06 : 09:22:20
Try Convert(VARCHAR(20),TRLogTime)+'_'+Convert(VARCHAR(20),TRLogDate)
Go to Top of Page

jmersing
Yak Posting Veteran

57 Posts

Posted - 2011-06-06 : 09:56:04
That did it, thanks so much !!
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-06-06 : 22:26:26
Why do you think that temporal data is strings? That was COBOL, not SQL. Use temporal math to get a timestamp out the two columns.

--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page
   

- Advertisement -