Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want a date but getting a blob

Status
Not open for further replies.

SBpsc

MIS
Dec 1, 2004
50
CA
Hi:

I am writing a query using MySQL and am running into some problems. Hopefully someone can help. My first query gets the year and month from the database and then concats them to create a datetime. When I run that query by itself, it displays the correct datetime format. However, when I union that query to another query which has real datetimes and then run the query, it does not show me a datetime anymore, rather it comes up as a blob. What am I doing wrong?

Code:
SELECT
   tb1.portal_id,
   CONCAT(tb12.TheYear,IF (tb11.TheMonth<10,'-0','-'),tb11.TheMonth,'-01 00:00:00') AS KeyDateTime
   ...
FROM
   portals AS tb1
...

UNION ALL

SELECT
   tb1.portal_id,
   tb2.StartDateTime,
   ...
FROM
   portals AS tb1
...

PS: The Month is retrieved from a column in the database which is INT unsigned. The Year is retrieved from a column in the database which is varchar(255).

Thanks in advance.
 
Well, thats a really intersting way you have of getting and storing dates, whatever is wrong with a field of type DATE ?

as for the query, I'll pass there's not really enough of it to make any sense(ible suggestions)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The field types in the union are determined by the field types in the first select. If you swap around the selects, that should work.
 
Thanks Tony, but that resulted in a blob too.
I did get it work by using the following:
Code:
FROM_DAYS(TO_DAYS(CONCAT(tb12.TheYear,IF (tb11.TheMonth<10,'-0','-'),tb11.TheMonth,'-01 00:00:00')))

...ugly, but its get the job done.

Thanks again,
SB
 
You could instead wrap the concat in a cast:[tt]
CAST(... as DATETIME)
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top