| Author |
Topic |
|
aks
Starting Member
28 Posts |
Posted - 2005-03-03 : 14:49:04
|
| Hi,I have a table with 3 columns as int,datetime & text.Int date text OUTPUT4 40 2004-09-06 2004-09-060 test test6 6I'm trying to get the OUTPUT column. select cast(a.date as varchar),cast(a.text as varchar),cast(b.text as varchar), cast(a.int as varchar),cast(b.int as varchar),casewhen a.textfield is null then a.dateelse b.dateend,CASEwhen a.textfield is null and a.date is null then a.intelse b.intendfrom secunsec a FULL OUTER JOIN secunsec bON a.uid=b.uidwhere (a.textfield<>0 or b.textfield <>0)AND (a.date <>0 or b.date <>0)But I'm getting error"Syntex error in converting text"test " to a data type int..What should I do????" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-03-03 : 14:56:29
|
| where (a.textfield<>0 or b.textfield <>0)s.b.where (a.textfield<>'0' or b.textfield <>'0')also(a.date <>0 or b.date <>0)s.b.(a.date <>'19000101' or b.date <>'19000101')or shiuld they be checking for null?==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
aks
Starting Member
28 Posts |
Posted - 2005-03-03 : 15:02:21
|
| I tried where (a.textfield<>'0' or b.textfield <>'0')and(a.date <>'19000101' or b.date <>'19000101')Its giving me no output..I think my query gets confused when a row int date text OUTPUT LOOKING FOR 0 test testcomes. Query tries to get together 0 & test..Is there any way I can make"0s" as null values.. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-03-03 : 15:05:47
|
| With thet data you have it won't give any output as you don't have 0 in any of those columns.What are you trying to do?==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
aks
Starting Member
28 Posts |
Posted - 2005-03-03 : 15:10:51
|
| I have a table with 3 columns as int,datetime & text.INT DATE TEXT OUTPUT LOOKING FOR"4" "" "" "4""0" "2004-09-06" "" " 2004-09-06""0" "" "test" " test""6" "" "" "6"I'm trying to get the last column "OUTPUT LOOKING FOR" |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-03-03 : 15:33:07
|
| No you don't "" is not a valid datetime.You will probably have '19000101' if you inserted an empty stringtryselect case when int = 0 then case when date = '19000101' then text else convert(varchar(20),date) else convert(varchar(20),int) endfrom tbl==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
aks
Starting Member
28 Posts |
Posted - 2005-03-03 : 16:05:06
|
| I made a viewcreate view varchar as select (casewhen a.val_textfield is null then a.val_dateelse convert(varchar(20),a.val_date)end) as date,(casewhen a.val_textfield is null and a.val_date is null then a.val_intelse convert(varchar(20),a.val_int)end) as int,(casewhen a.val_date is null and a.val_int=0 then a.val_textfieldelse convert(varchar(20),a.val_textfield)end) as addressfrom secunsec a FULL OUTER JOIN secunsec bON a.uid=b.uidwhere (a.uid<>0 or b.uid<>0)After this I write the query:select case when a.address is null and a.int ='0 'then a.datewhen a.date is null and a.address is null then a.intwhen a.date is null and a.int='0' then a.addresselse a.addressendfrom varchar a FULL OUTER JOIN varchar bON a.uid=b.uidBut Still I got the error"Syntex error converting datetime from character string". I have already converted data types for column in VARCHAR view. I'm wondering why it is giving me again conversion error" |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-03-03 : 16:08:45
|
| Why are you using a join at all? Did you look at my response?The error here is because the case statement needs to return a datatype. As there is a datetime in it and this has the highest precedance then it will convert everything to datetime.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|