zahid_7777 (10/8/2012)
I just like to know the command to copy data (specific range like 10 rows) containing in a COMPANY_CODE and will be copied to another COMPANY_CODE starting with a new accounts_code which will be different from the previous accounts_code in a same dbo.ACCOUNT_INFO table.Structure of the table like
COMPANY_CODE ACCOUNTS_CODE ACCOUNTS DESCRIPTION
0001 18-01-0001-001 AR-SALEs ASSETS
0001 18-01-0001-002 AR-X ASSETS
0002 18-01-0001-001 AR-y ASSETS
0002 18-01-0001-002 AR-y ASSETS
last two record should be coppied to the company code 0001 starting from a defined account code and continue to add with by incremented by in the accounts code.
-- please provide us with the business rules
-- for generating the new account codes
INSERT INTO MyTable (
COMPANY_CODE,
ACCOUNTS_CODE,
[ACCOUNTS DESCRIPTION])
SELECT
COMPANY_CODE = '0001',
ACCOUNTS_CODE = ?, <<====
[ACCOUNTS DESCRIPTION]
FROM MyTable
WHERE COMPANY_CODE = '0002'
AND ACCOUNTS_CODE IN ('18-01-0001-001','18-01-0001-002')
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden