| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

05-25-11, 14:55
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 21
|
|
|
Concat + time_format???
|
|
hi,
i need to concat two columns aswell as perform a time_format on them, struggling with syntax, heres what i have:
SELECT CONCAT(stf.forename, ' ', stf.surname) AS Name, DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date,
TIME_FORMAT(CONCAT(shf.start_time, '-', shf.end_time, '%H - %i %p')) as Shift
FROM staff stf, shift shf, staff_shift ss
WHERE shf.shiftID = ss.shiftID
im getting the error
"Incorrect parameter count in the call to native function 'TIME_FORMAT'"
returned
please help!!!
|
|

05-25-11, 16:52
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
|
|
Have a look at your second TIME_FORMAT function:
SELECT CONCAT(stf.forename, ' ', stf.surname) AS Name, DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date,
TIME_FORMAT(CONCAT(shf.start_time, '-', shf.end_time), '%H - %i %p') as Shift
FROM staff stf, shift shf, staff_shift ss
WHERE shf.shiftID = ss.shiftID
|
|

05-25-11, 17:14
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 21
|
|
|
|
thanks for the reply!
i've got a result, which is great however the two 'times' are failing to concatenate in the column
|
|

05-25-11, 18:58
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
what datatypes are the start_time and end_time columns? could we see sample values?
|
|

05-26-11, 09:53
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 21
|
|
the 'start_time and end_time are both 'TIME' datatypes, example entries would be 09:00:00 and 21:00:00
|
|

05-26-11, 12:50
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
oh, i see
could you please explain what you were trying to do here...
Code:
TIME_FORMAT(CONCAT(shf.start_time, '-', shf.end_time), '%H - %i %p') as Shift
|
|

05-26-11, 17:27
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 21
|
|
the two columns need to be concatenated, its to display a shift for someone. Rather than have it displayed as 'start_time 09:00:00' as one column and 'finish_time 21:00:00' as another, i thought it would be be better for the end user user to be able to read it as just 'Shift 9:00 am - 9:00pm' (24 hour format is a possible alternative)
|
|

05-26-11, 17:34
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
okay, i understand
try this --
Code:
SELECT CONCAT(stf.forename,' ',stf.surname) AS Name
, DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date
, CONCAT(TIME_FORMAT(shf.start_time,'%h:%i %p')
,' - '
,TIME_FORMAT(shf.end_time),'%h:%i %p')
) AS Shift
FROM ...
|
|

05-26-11, 17:45
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 21
|
|
r937, ever a legend!! it works! thank you so much!!
just to tie it up there was one bracket missing..
SELECT CONCAT(stf.forename,' ',stf.surname) AS Name
, DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date
, CONCAT(TIME_FORMAT(shf.start_time,'%h:%i %p')
,' - '
,TIME_FORMAT((shf.end_time),'%h:%i %p')
) AS Shift
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|