Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
* appearing as total
Message
From
25/11/1999 17:20:39
 
 
To
25/11/1999 16:57:59
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00295641
Message ID:
00295646
Views:
29
>>Here is my query:
>>
>>select distinct instructor.instructorid, course.courseid, studentcourse.sckey,;
>>(iif(studentcourse.ispaid = .T.,(course.hours * paymodel.rate) *
>>count(studentcourse.courseid),0)) as total;
>> from course left join studentcourse on course.courseid = studentcourse.courseid;
>> left join instructor on studentcourse.instructorid = instructor.instructorid;
>> left join paymodel on instructor.training = paymodel.traintype;
>>into cursor temppay;
>>group by course.courseid
>>
>>This gives me all the courses even if they don't have an instructor. I then want to check if in the studentcourse table if the ispaid field is true. If it is I want to total up how much they are to be paid. If not they get 0 for that student. The total is 0 for all the ones that ispaid = .F. but the ones that equal true the total field equals a star(*). Does anyone know why this is happening? I don't know if it really makes sense.
>>
>>Thanks in advance,
>>Tyler
>
>When the SELECT-SQL statement is run, the Total column gets its width from the FIRST row in the selected result. Your first row value for Total is 0, so the column is being set to N(1, 0). Subsequent non-zero values are overflowing, hence the *.
>
>If you have an idea of the range of values encompassed by Total, you can use something like
>
>>select distinct instructor.instructorid, course.courseid, studentcourse.sckey,;
>>(iif(studentcourse.ispaid = .T.,(course.hours * paymodel.rate) *
>>count(studentcourse.courseid),<i>000000.00</i>)) as total;
>>	from course left join studentcourse on course.courseid = studentcourse.courseid;
>>		left join instructor on studentcourse.instructorid = instructor.instructorid;
>>		left join paymodel on instructor.training = paymodel.traintype;
>>into cursor temppay;
>>group by course.courseid
>
>
>This forces/tells the SELECT-SQL what width/precision to use for the column.

I just realized this is only half an answer. What if your first row is a small, non-zero value then in a later row you have a larger value? It will also appear as *.

A better answer would be to force the width/precision of the column regardless of the result of the IIF():
select distinct instructor.instructorid, course.courseid, studentcourse.sckey,;
<b>VAL(STR(</b>(iif(studentcourse.ispaid = .T.,(course.hours * paymodel.rate) *
count(studentcourse.courseid),0))<b>, 8, 2))</b> as total;
	from course left join studentcourse on course.courseid = studentcourse.courseid;
		left join instructor on studentcourse.instructorid = instructor.instructorid;
		left join paymodel on instructor.training = paymodel.traintype;
into cursor temppay;
group by course.courseid
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform