Basically I’d like to get this command to work:
$sql = "SELECT (EntryDate + TotalTime) as DataLine FROM TimeSheet WHERE EmployeeID='AA01'";
EntryDate is in the database as a text, but TotalTime is a Number. I need to cast TotalTime as a text, because I’ve noticed if I combine two differing types of values, it just blanks out the output.
I know I’m supposed to use CAST(TotalTime as XXX) but I’m not sure what I can legally cast it to (char/nchar doesn’t seem to work, neither does string nor text). I always get an error of the form…
Syntax error (missing operator) in query expression '(EntryDate + CAST(TotalTime as string) as DataLine FROM TimeSheet WHERE EmployeeID='AA01''
Could I get some help? Thank you!
EDIT I would like to note this isn’t intended to add together the values of EntryDate and TotalTime together to produce a single value. I simply want it to give me the EntryDate value as well as the TotalTime value combined into a single line that would read something like:
“10/31/12 9.25”
EDIT AGAIN I’m sorry for not specifying before, I’m using MSSQL
Try this instead:
However, if
entrydateis a date and the inttotaltimeis a time, it may be better to consider converting them as a datetime object by adding them as a date part to the time part depending on the RDBMS you are using. And if possible use aDATETIMEdatatype to represent both date and time parts instead of two parts. Like so:SQL Fiddle Demo