Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 3 Jahren, 5 Monaten
Letzter Beitrag:
vor 3 Jahren, 2 Monaten
Beteiligte Autoren:
Vijay Patel, Paulo Oliveira, Yogi Yang, DerekT, Peter Holemans, Fabrice Harari, Allard

random record found in database table

Startbeitrag von Vijay Patel am 04.01.2015 14:29

SELECT
ExamData.ExamDataID AS ExamDataID,
ExamData.Index_Id AS Index_Id,
ExamData.ED_Que AS ED_Que,
ExamData.ED_Ans_A AS ED_Ans_A,
ExamData.ED_Ans_B AS ED_Ans_B,
ExamData.ED_Ans_C AS ED_Ans_C,
ExamData.ED_Ans_D AS ED_Ans_D,
ExamData.ED_currectAns AS ED_currectAns
FROM
ExamData
ORDER BY
Index_Id RAND
LIMIT 100


--------------------
i am try to above query excu. but this query in give error windev17


please give help me

Antworten:

Hi

1. What error ?
2. What code do you use to run this query?
3. On what type of database?

Are we supposed to devine all that?

Best regards

von Fabrice Harari - am 04.01.2015 14:40
database id hyperfile

does not generat query

error is unexpected word:RAND()

von Vijay Patel - am 05.01.2015 05:26
Hi Vijay ,

If you donnot give us more information we cannot help you.

Is there an error or does the query generate other results then you expect?
How do you run the query, what code?
Do you use hyperfile cs ?



Vijay you are a programmer. Then you know that for fixing bugs one first has to uderstand what you want to atchief. If an error is displayed then moast of the time you are doing something wrong, but it can be a windev bug as well. If there is no error but other results then you expect then you have to try to figgert out why this is. I often first try to run only the query , for instance in the hyperfile cs if you made the query yourself.

It is all about excluding things that are good an thus the fault remains and you can focus on that

You problebly know all this . But in my opinion far to often forum users post verry little info and expect a result form other users. If you spent the time and be as specific as possible you are moast likely get an answer for the users on this forum in general are verry helpfull en willing to help individuals.

regards
Allard

von Allard - am 05.01.2015 10:01
Hi,

1. What does ErrorInfo(hErrFullDetails) tell you?
2. Do you have the hQueryWithoutCorrection parameter flagged?
3...

Cheers,

Peter H.

von Peter Holemans - am 05.01.2015 10:09
VIjay,

I have never used this feature but I think there is no facility to randomize results of a Query in HFSQL. Generally in MySQL there is an SQL function RAND() so it would be possible to use it in ORDER BY clause of a select query.

Here is a sample query that I have used in retrieving and showin Ad in a website

SELECT ad_content_image, ad_link, ad_id, ad_count FROM advertisement WHERE ad_approve = 1 AND ad_content_type_id = 1 AND (ad_lifetime = 1 OR DATE(ad_end_date) > DATE(NOW())) ORDER BY RAND() LIMIT 1


What you can do is retrieve data as usually one would using query and then populate the controls by accessing the data retrieved randomly.

HTH

Yogi Yang

von Yogi Yang - am 05.01.2015 10:18
Vijay

Your error explains the problem

RAND() is not supported in the HFSQL language.

2 options...
1. Change to a database that does support it (MySQL, MSSQL etc)

2. Load your query result into an array and use 'ArrayMix' - The type of array you choose depends the number of rows returned on how you need to display the result.
A bit more work but an 'array of structures' would IMHO be the way to go

Just noticed: Item 2 requires version 19

von DerekT - am 05.01.2015 11:08
You can try something like this:
SELECT
ExamData.ExamDataID AS ExamDataID,
ExamData.Index_Id AS Index_Id,
ExamData.ED_Que AS ED_Que,
ExamData.ED_Ans_A AS ED_Ans_A,
ExamData.ED_Ans_B AS ED_Ans_B,
ExamData.ED_Ans_C AS ED_Ans_C,
ExamData.ED_Ans_D AS ED_Ans_D,
ExamData.ED_currectAns AS ED_currectAns,
random() as ra
FROM
ExamData
ORDER BY
ra

von Paulo Oliveira - am 05.01.2015 12:36
thank you sir

von Vijay Patel - am 06.01.2015 13:35
hi,paulo oliveira
i am try this code but that is return same racord
i get deff.record in run any time..
that is same record give any time run program...

SELECT
ExamData.ExamDataID AS ExamDataID,
ExamData.Index_Id AS Index_Id,
ExamData.ED_Que AS ED_Que,
ExamData.ED_Ans_A AS ED_Ans_A,
ExamData.ED_Ans_B AS ED_Ans_B,
ExamData.ED_Ans_C AS ED_Ans_C,
ExamData.ED_Ans_D AS ED_Ans_D,
ExamData.ED_currectAns AS ED_currectAns,
random() as ra
FROM
ExamData
ORDER BY
ra

von Vijay Patel - am 15.01.2015 08:38
I didn't test it but probably you have to use InitRandom() before executing the query.

von Paulo Oliveira - am 15.01.2015 09:35
thank you
sir.

von Vijay Patel - am 13.04.2015 17:32
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.