Carlos Savoretti wrote:

Hello all:

I need to make certain operations like this:

select tbl_no as 'Number' , @sal1 := tbl_db - tbl_hb + @sal1 as 'Total'

I'm using the C API; so I make it through mysql_query()

Problem is than having `tbl_db' and 'tbl_hb' with certain values no

operation is carried out, and `Total' is NULL.

What am I doing bad ?

Please, help me

Thanks all

Carlos Savoretti
[EMAIL PROTECTED]

@sal1 is NULL until you assign it a value. Your assignment is self-referential.


  @sal1 := tbl_db - tbl_hb + @sal1

On the first pass, then, that's

  @sal1 := tbl_db - tbl_hb + NULL

Anything plus NULL is NULL, so you get

  @sal1 := tbl_db - tbl_hb + NULL

on every subsequent pass, as well.

You need to start with

  SET @sal1 = 0;

first.

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to