House of Fusion
Home of the ColdFusion Community

Search cf-talk

October 07, 2008

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Subscribe Now
Fusion Authority Quarterly Update - ColdFusion 8 Special Edition
Search over 2,500 ColdFusion resources here  >>>      
Home /  Groups /  ColdFusion Talk (CF-Talk)

simple select query not working

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
hi
Richard White
07/08/08 03:08 P
Richard White wrote:
Ian Skinner
07/08/08 03:47 P
Hi Ian,
Richard White
07/08/08 04:05 P
thanks for all your help
Richard White
07/09/08 06:52 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 03:08 PM

hi i have a query in cf and want to run another very simple query on it and for some reason it is not getting the data that i know is in there: first i am running this query (i am using query of query for these queries): select qu_80_tb_89_split_0_split_T_Wt from mergedColumnsQuery where subjectID = 446 and projectID = 36 and testOccasionID = 2 and qu_80_tb_89_split_0_split_T_Ht is null and qu_82_tb_89_split_0_split_T_Ht = 147.0; and it is returning a value that i know that is in there. but then when i run the following statement which is identical to the one above except a couple of changes in the where clause it doesnt produce any data although i have checked the data many times and it should definately return a result: select qu_80_tb_89_split_0_split_T_Wt from mergedColumnsQuery where subjectID = 447 and projectID = 36 and testOccasionID = 2 and qu_80_tb_89_split_0_split_T_Ht is null and qu_82_tb_89_split_0_split_T_Ht = 142.2; thanks for any suggestions richard

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Qing Xia
07/08/2008 03:29 PM

Hmmm... if it is a query of query, then you are limited to what the parent query (sorry, don't really know what the first query from DB is called...) has.  So, even if a row of data does exist in a table, if that row of data is not pulled by the parent query, then there is no way how you can get it through any query of query based on the parent query. Now, if you look at the query result of the parent query, is the desired row of data in it? ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 03:33 PM

yes i have dumped out the query named mergedColumnsQuery just before i run the cfquery select statement on that query and it does contain a row with the data that i am trying to select would it have anything to do with column types? thanks ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
07/08/2008 03:47 PM

Richard White wrote: > yes i have dumped out the query named mergedColumnsQuery just before i run the cfquery select statement on that query and it does contain a row with the data that i am trying to select > > would it have anything to do with column types? > > thanks Well the first thought I had was can one do "NULL" in a query of query?   I wonder because CF does not normally grock 'NULL' and null columns from a database are 'empty strings' in ColdFusion record sets. You might try changing your 'IS NULL' comparisons to = ''.  (equal empty string) comparisons. But why the first works with IS NULL and the second doesn't, I do not understand.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 04:05 PM

Hi Ian, yes i did start off comparing with empty strings - like where xx = "" but i wont always know the data type of the column and therefore i get an error if the column data type is an integer for example, so i thought that by adding 'is null' will then work for all column types. if anyone sees a better way of doing this and that this may be unreliable i will appreciate it, as i dont know how else to compare an integer column with no data? thanks ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 04:14 PM

>Try: LEN(RTRIM(LTRIM(my_integer_column))) = 0 thanks ill use this

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Qing Xia
07/08/2008 03:48 PM

Hmm... interesting.  I thought about data types, but if a column is varchar and you are not enclosing the data for it in single quotes, the query should still return the rows. For example, if you did SELECT * FROM myTable WHERE myRow = 1 and myRow is actually a VARCHAR column, all rows of myRow = 1 should still be returned. Probably not the best practice, but should work... Not sure how it behaves though if the value is a decimal stored in varchar and you are not enclosing it in single quotes.  Might be worth a try. Here's a strategy: comment out  condition in your WHERE clause one at a time.  This way you can see the exclusion of which condition gives you the desired the result, then you can use that as a clue ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 03:55 PM

thanks Qing, getting there now!!! after what you said i commented them out one by one and it only fails when it gets to the last column which is: and qu_82_tb_89_split_0_split_T_Ht = 142.2; so i then used a function i got from cflibs called queryColumnTypes and found that the column is a 'Real' data type. would this have something to do with it, i cannot work out why this is Real instead of a double or decimal - it is a float in the database when i first queried it, so does cf convert them to a 'real' and do you think this is the cause thanks ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Qing Xia
07/08/2008 04:06 PM

Wow.  That is wild! I have never experienced where a column is one data type in a SQL server table and then changed to something else after CF pulls it... (Except for NULL of course, there is no NULL in CF) Beats me! I can't imagine why this is happening... But, just for kicks... change that troublesome condition to: and qu_82_tb_89_split_0_split_T_Ht = 142.20 and see if it gets you anything. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 04:15 PM

thanks for your help anyway Qing, i cannot work this out either, i cannot see why the first one would work but not the second thanks ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 04:19 PM

>dont know if it may apply but to get that column i did a left join with another query and then from that query i did a union with another query so i will backtrack through all of these to see at what point it is changed and see where i can fix it thanks

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Qing Xia
07/08/2008 04:28 PM

Speaking of left outer joins:  when you have a left outer join, and then you put a condition for the right-hand-side table in the WHERE clause, then that turns the LEFT OUTER JOIN into an INNER JOIN. For exmaple, the following two queries will return the same result: select  ta.ta_id,        ta.columnA1,         ta.columnA2,        tb.tb_id,         tb.columnB1,         tb.columnB2 from tableA ta left outer join tableB tb   on ta.ta_id = tb.tb_id where tb.columnB1 = 100 select  ta.ta_id,        ta.columnA1,         ta.columnA2,        tb.tb_id,         tb.columnB1,         tb.columnB2 from tableA ta inner join tableB tb   on ta.ta_id = tb.tb_id where tb.columnB1 = 100 So you might want to check whether a left join clause could have been accidentally placed in the WHERE clause. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 05:17 PM

i tried changing all the columns to data types of varchar and then to query this data by surrounding the where clause data with '' and this now produces an error saying: Error casting an object of type  to an incompatible type. This usually indicates a programming error in Java, although it could also mean you have tried to use a foreign object in a different way than it was designed. can anyone suggest another way round this? thanks ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/09/2008 06:52 PM

thanks for all your help ben nadal managed to identify the problem as being the column types and using the following casting worked fine: CAST(qu_82_tb_89_split_0_split_T_Ht AS DECIMAL) = CAST(142.2 AS DECIMAL)

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Brad Wood
07/08/2008 03:37 PM

Are you sure the qu_80_tb_89_split_0_split_T_Ht column is really NULL, and not just an empty string? ~Brad yes i have dumped out the query named mergedColumnsQuery just before i run the cfquery select statement on that query and it does contain a row with the data that i am trying to select would it have anything to do with column types?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard White
07/08/2008 03:49 PM

hi brad, even if i leave out that column and just add the select statement: select qu_80_tb_89_split_0_split_T_Wt from mergedColumnsQuery where subjectID = 447 and projectID = 36 and testOccasionID = 2 and qu_82_tb_89_split_0_split_T_Ht = 142.2; it still doesnt find the row - and just before i run the statement i have dumped the query i am selecting from and there is a row with those items in. i have never seen anything like this before!!!

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Brad Wood
07/08/2008 03:54 PM

I'm going to go with Qing Xia's suggestion here. Start with nothing but select qu_80_tb_89_split_0_split_T_Wt from mergedColumnsQuery and add the where pieces back in one at a time until the record goes away. ~Brad hi brad, even if i leave out that column and just add the select statement: select qu_80_tb_89_split_0_split_T_Wt from mergedColumnsQuery where subjectID = 447 and projectID = 36 and testOccasionID = 2 and qu_82_tb_89_split_0_split_T_Ht = 142.2; it still doesnt find the row - and just before i run the statement i have dumped the query i am selecting from and there is a row with those items in. i have never seen anything like this before!!!


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists