|
-
May 19th, 2011, 10:22 AM
#1
Thread Starter
Addicted Member
Select Query
I'm working on a vb.net application, where I use sql queries to get the datas from a dbase file.
There are cases where there can be 2 similar rows with the PARENT and ENFANT fields same in E_Ensart table, but the other columns may ahve different datas.
I use the below query to retrive datas from the database:
Code:
Private Function GetSQLExactMatch(ByVal name As String, ByVal artTbl As String) As String
Dim sb As StringBuilder = New StringBuilder("")
sb.Append(GetSQLSelectColumns())
sb.Append(" from E_Ensemb e, ")
sb.Append(" E_Ensart a ")
sb.Append(" where a.PARENT = '" & name & "' ")
sb.Append(" and e.ITEM_NBR = a.ENFANT ")
sb.Append(" and a.VALIDITE = 'O'")
Return sb.ToString()
End Function
When I use the above query, I get only one line from E_Ensart table instead of 2 lines.
I think its because I assign the e.ITEM_NBR =a.ENFANT in my query.
But even if I remove this line, I get only one row picked instead of 2 rows and I also find that the query is running indefinitly and the same line is repeated n number of times...
Kindly help me to find out where I'm wrong.
Hoping for suggestions.
Thanks in advance.
-
May 19th, 2011, 11:53 AM
#2
Re: Select Query
What happens when you put the output of sb.ToString() into the clipboard and you run the query directly in the database? Do you still only get 1 record or do you get both? Does the query even look right?
-
May 19th, 2011, 12:09 PM
#3
Thread Starter
Addicted Member
Re: Select Query
Thanks for your reply.
I get only 1 line.
I think the query is wrong as I said before.
I think its because I assign the e.ITEM_NBR =a.ENFANT in my query.
But even if I remove this line, I get only one row picked instead of 2 rows and I also find that the query is running indefinitly and the same line is repeated n number of times...
Thanks in advance for any help.
-
May 19th, 2011, 12:22 PM
#4
Re: Select Query
You do realize that other than the questions I've already asked, we have no idea how to help you unless you post the query & an example of the data, right?
-
May 19th, 2011, 12:26 PM
#5
Thread Starter
Addicted Member
Re: Select Query
I'm out of office now.
I don't have the data now.
Will get back to you tomorrow with the details.
Please do have a look at my post tomorrow.
Thanks.
-
May 20th, 2011, 01:50 AM
#6
Thread Starter
Addicted Member
Re: Select Query
Data from my table:
Code:
PARENT ENFANT SECT_GRP NPR_DC_NBR CD_ST UTIL_IND IND_REP BALOON DNF DATE_REEL ADD_SUP UTIL_QTE DC_ANNU DATE_ANNU VALIDITE FLAG_ALT CODE_MODIF
4353742M92 3778094M1 AA F28900051 E D N 2/24/2011 A 008 O
4353742M92 4298199M1 AA F28900051 E D N 2/24/2011 A 002 O
4353742M92 4348342M1 AA F28900051 E D N 2/24/2011 A 002 O
4353742M92 4348661M2 AA F28900051 E D N 2/24/2011 A 002 O
4353742M92 4349709M1 AA F28900051 E D N 2/24/2011 A 002 O
4353742M92 4353749M1 AA F28900051 E D N 2/24/2011 A 002 O
4353742M92 4353745M2 AA F28900051 E D N 2/24/2011 A 002 O
4353742M92 4356943M1 A F28900051 E D N A 4353742M92 2/24/2011 A 001 O
4353742M92 4353745M2 B F28900051 E D N B 4353742M92 2/24/2011 A 001 O
The lines marked in red has to appear 2 times in my output, whereas, I get only one line(the 1st occurance of the line).
Thanks for any suggestion.
-
May 20th, 2011, 03:16 AM
#7
Re: Select Query
Try querying the database directly for each table, then both tables using a DB tool to check that your query is logically correct before trying to implement it at your front-end.
If parent table only has one relevant row, and child has only one rows with VALIDITE = 'O' then it is expected that you will get only one row in result of join e.ITEM_NBR = a.ENFANT.
-
May 20th, 2011, 03:50 AM
#8
Thread Starter
Addicted Member
Re: Select Query
Thanks for the reply.
To get all the rows where a.PARENT='" & name & "' ( as value passed)
what should be done?
Code:
sb.Append(" where a.PARENT = '" & name & "' ")
Thanks
-
May 22nd, 2011, 06:25 PM
#9
Re: Select Query
if you want to retain all child records then do a left join on e.ITEM_NBR = a.ENFANT and remove validite condition.
-
May 23rd, 2011, 02:06 AM
#10
Thread Starter
Addicted Member
Re: Select Query
Thanks for the suggestion.
I did a left join as follows:
Code:
sb.Append(" from E_Ensemb e ")
sb.Append(" left join E_Ensart a on a.ENFANT = e.ITEM_NBR ")
sb.Append(" where a.PARENT = '" & name & "'")
but still I get only one line instead of 2.
Please help.
-
May 23rd, 2011, 03:02 AM
#11
Re: Select Query
Try running your query dirctly on the database. Check if the result is correct. It's possible that query is correct but front end control property or code is filtering out the other rows.
Divide and conquer.... eliminate possibilities.
-
May 23rd, 2011, 03:09 AM
#12
Thread Starter
Addicted Member
Re: Select Query
yes, I ran the query directly on the database and I get 9 rows where 2 rows has the same value in the ea.ENFANT.
When I do the same query in vb.net, I get 8 rows and only 1 row instead of 2 rows where there is same value in the ea.ENFANT column.
How to handle it with the vb.net front end.
query used directly on access tables:
Code:
SELECT ea.PARENT, ea.ENFANT, ea.BALOON, ea.DNF, ea.UTIL_QTE, e.DES_F, e.DES_AD_F, e.DES_A, e.DES_AD_A
FROM E_Ensart1 AS ea, E_Ensemb1 AS e
WHERE ea.ENFANT=e.ITEM_NBR and ea.PARENT='4353742M92';
Any help will be helpful.
working on this for the past 4 days with no result...
Thanks in advance.
Last edited by vijay2482; May 23rd, 2011 at 03:15 AM.
-
May 23rd, 2011, 08:00 PM
#13
Re: Select Query
If the query is correct in the database then the problem is at your front-end. Check the properties of your controls; maybe it is set to display distinct rows only. Check your triggered events; they might be rewriting the query. Related to dynamic rewrite, check text of query just before execution in the database (dump it so you can view the query), don't base exclusively on SQL you are building elsewhere in code. If you are not using data bound controls then check your algorithm for transferring info fr0om recordset to display grid. If you are using a non-standard control then it might have bugs. etc, etc
AGAIN if the query returned correct resultset when ran directly against the database then the problem is NOT the query. It is something else at your front-end.
Last edited by leinad31; May 23rd, 2011 at 08:04 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|