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.
| Author |
Topic |
|
RichardSteele
Posting Yak Master
160 Posts |
Posted - 2007-04-24 : 11:53:39
|
| I want to merge data from two different tables that have the same column names but different datatypes.Table one has a varchar field pubdate_full that includes a date formatted as text like this: '2005-04-15'. Table two has a smalldatetime field called Hard_NYP and a varchar pubdate field that includes just the year (eg '2007').I want to Select data in table two and return a pubdate_full field that has either the datepub or the Hard_due. If the Hard_due is not null or '1/1/1900 12:00:00 AM' then I want to fill pubdate_full with that value, otherwise fill it with the pubdate value.This works in that regard:SELECT Hard_due, datepub CASE WHEN (Hard_due <> '1/1/1900 12:00:00 AM') AND (Hard_due IS NOT NULL) THEN Hard_Due ELSE datepub END AS pubdate_full from inventory The question is, how do I convert pubdate_full on the fly to be the same format and datatype as the Table one pubdate_full or vice versa in order to be able to merge the two tables?Many thanks in advance. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-24 : 12:10:34
|
just use convert(datetime, pubdate_full) KH |
 |
|
|
|
|
|