Solved

transferring old records to new table, but calculating (incrementing) lead ordinals per lead id

Posted on 2012-03-27
2
309 Views
Last Modified: 2012-03-27
hi.
i am not sure if this can be done through a single mysql query, but it was attempted as follows:
// update test transactions table
$sql10 = "INSERT INTO 
			dwtphovu_8347379386_test.8_transactions 
			(
				bigint_TransactionID,
				text_TransactionEvent,
				bigint_SupplierID,
				bigint_LeadID,
				bigint_TransactionAmount,
				bigint_TransactionBalance,
				timestamp_TransactionEvent,
				smallint_LeadOrdinal
			) 
		SELECT 
			PTR.bigint_TransactionID,
			PTR.text_TransactionEvent,
			PTR.bigint_SupplierID,
			PTR.bigint_LeadID,
			PTR.bigint_TransactionAmount,
			PTR.bigint_TransactionBalance,
			PTR.timestamp_TransactionEvent, 
			#insert integers counting from 0 here, per lead id.
		FROM 
			dwtphovu_8347379386_prod.8_transactions PTR;";
$result10 = mysql_query_errors($sql10, $conn , __FILE__ , __LINE__ , true );

Open in new window

if this can be done only via php/mysql combined - how would this be achieved?
0
Comment
Question by:intellisource
  • 2
2 Comments
 

Accepted Solution

by:
intellisource earned 0 total points
ID: 37772343
i'm wondering now, wether it would help to select a count with the insert of each record from the old table - for example:
// update test transactions table
$sql10 = "INSERT INTO 
			dwtphovu_8347379386_test.8_transactions 
			(
				bigint_TransactionID,
				text_TransactionEvent,
				bigint_SupplierID,
				bigint_LeadID,
				bigint_TransactionAmount,
				bigint_TransactionBalance,
				timestamp_TransactionEvent,
				smallint_LeadOrdinal
			) 
		SELECT 
			PTR.bigint_TransactionID,
			PTR.text_TransactionEvent,
			PTR.bigint_SupplierID,
			PTR.bigint_LeadID,
			PTR.bigint_TransactionAmount,
			PTR.bigint_TransactionBalance,
			PTR.timestamp_TransactionEvent, 
			(
				SELECT 
					COUNT(TT.smallint_LeadOrdinal) AS smallint_LeadOrdinal
				FROM 
					dwtphovu_8347379386_test.8_transactions TT 
				WHERE 
					TT.bigint_LeadID = PTR.bigint_LeadID
			)
		FROM 
			dwtphovu_8347379386_prod.8_transactions PTR;";
$result10 = mysql_query_errors($sql10, $conn , __FILE__ , __LINE__ , true );

Open in new window

0
 

Author Closing Comment

by:intellisource
ID: 37772939
and it seems to work beautifully ;)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question