Posted by: prajapatinilesh | January 7, 2011

Marge 2 field Sybase query

TableName: ScheduledHomepage
Fields: startDate (datetime) , startHour (time)

select startDate,startHour from ScheduledHomepage
startDate                  startHour
————————– —————
NULL            NULL
May 15 2010 12:00AM         10:00AM
Mar 11 2010 12:00AM          9:00AM

//Trancate time value from full date time value.
select left(startDate,11) as startDate from ScheduledHomepage

startDate
———–
NULL
May 15 2010
Mar 11 2010

//Combine 2 field value
select left(startDate,11) +” “+ convert(varchar(8), startHour) as startDateTime from ScheduledHomepage

startDateTime
——————–

May 15 2010 10:00AM
Mar 11 2010  9:00AM

Other sample examples:

select convert(nvarchar,getdate(),101)
select convert(INT,convert(varchar,getdate(),112))
SELECT LEFT(DateTimeField, 11) FROM Table
SELECT CONVERT(VARCHAR(20), DateTimeField, 101) FROM YourTable

Thanks,

Nilesh Prajapati

Advertisements

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

Categories

%d bloggers like this: