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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query help

Author  Topic 

cruxmagi
Starting Member

38 Posts

Posted - 2008-07-28 : 07:44:23
Can you help me out to combine two columns as a single column
Ex: select (starttime,endtime) as schedule from schedule
Expected Result
Schedule
2008-07-28 17:12:28.400 2008-09-28 17:12:28.400
2008-07-28 17:12:28.400 2008-09-28 17:12:28.400

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-28 : 07:49:02
how do you want to combine them ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-28 : 07:52:43
check this,

SELECT CONVERT(VARCHAR(25), starttime,121)+' '+CONVERT(VARCHAR(25), endtime,121) from schedule
Go to Top of Page

cruxmagi
Starting Member

38 Posts

Posted - 2008-07-28 : 07:53:13
ex: If start date is 2008-07-28 and end date is 2008-09-28 ,i need to select like
schedule
2008-07-28 2008-09-28
Go to Top of Page

cruxmagi
Starting Member

38 Posts

Posted - 2008-07-28 : 07:54:55
quote:
Originally posted by VGuyz

check this,

SELECT CONVERT(VARCHAR(25), starttime,121)+' '+CONVERT(VARCHAR(25), endtime,121) from schedule




tx
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-28 : 07:58:55
Hi,
Check this

SELECT replace(CONVERT(VARCHAR(10), GETDATE(), 111) ,'/','-')+' '+replace(CONVERT(VARCHAR(10), GETDATE(), 111) ,'/','-')AS [YYYY-MM-DD]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-28 : 08:32:06
quote:
Originally posted by cruxmagi

quote:
Originally posted by VGuyz

check this,

SELECT CONVERT(VARCHAR(25), starttime,121)+' '+CONVERT(VARCHAR(25), endtime,121) from schedule




tx


make usre you check for NULL values also just in case the datefields are nullable

SELECT COALESCE(CONVERT(VARCHAR(25), starttime,121)+' ','') + COALESCE(CONVERT(VARCHAR(25), endtime,121),'') from schedule
Go to Top of Page
   

- Advertisement -