CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Increment based on the value of another column (SOLVED)

Print topic Send  topic

Author Message
skysigma

Posts: 24
Posted: 09/28/2014, 6:02 PM

Hi there

I have a situation like that:

id_1 | id_2
------------------
1 | 1
1 | 2
1 | 3
2 | 1
3 | 1
3 | 2

How can auto-increment the value of the id_2 based on the value of id_1?
Thanks

Marco
View profile  Send private message
jekes

Posts: 36
Posted: 09/29/2014, 2:56 AM

Hi,

You can do this with the query SELECT id_1 + n AS id_2
Or in the BeforeShow Row event you can retrieve the value of id_1 and change the value of the id_2 with the new one.

View profile  Send private message
skysigma

Posts: 24
Posted: 09/29/2014, 12:02 PM

I used the following trigger

BEGIN
DECLARE counter INT;
SELECT COALESCE(MAX(id_2),0)+1
INTO counter FROM table WHERE id_1 = NEW.id_1;
SET NEW.id_2=counter;
END
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.