Created
October 23, 2018 13:44
-
-
Save nikolasd/b90c1d38e6391a8a74928d13a6da1d09 to your computer and use it in GitHub Desktop.
Αντιγραφή σειρών από υποκατάστημα
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1. Backup HeDocSeries | |
*/ | |
INSERT INTO hedocseries_bak | |
SELECT | |
* | |
FROM hedocseries | |
/* | |
* | |
* Series Type List | |
* | |
0 Πωλήσεις | |
1 Αγορές | |
2 Είδη | |
3 Εισπράξεις πελατών | |
4 Εισπράξεις χρεωστών | |
5 Πληρωμές προμηθευτών | |
6 Πληρωμές πιστωτών | |
7 Λοιπά πελατών | |
8 Λοιπά χρεωστών | |
9 Λοιπά προμηθευτών | |
10 Λοιπά χρεωστών | |
11 Λοιπά τραπεζικών λογαριασμών | |
12 Κινήσεων τραπεζικών λογαριασμών | |
13 Κινήσεων αξιογράφων | |
14 Συμψηφισμοί πελατών | |
15 Συμψηφισμοί χρεωστών | |
16 Συμψηφισμοί προμηθευτών | |
17 Συμψηφισμοί πιστωτών | |
18 Δαπανών / Χρεώσεων | |
19 Λοιπά χρηματικών λογαριασμών | |
20 Συμψηφισμοί χρηματικών λογαριασμών | |
21 Πολλαπλού σκοπού | |
*/ | |
/* | |
* | |
* Used By Module List | |
* | |
0 Κανένα | |
1 Λιανική | |
2 Ξενοδοχείο | |
3 Mobile | |
*/ | |
/* | |
2. Copy current shortcut to name for shortcuts that exceed the max length | |
You can always check before executing with | |
SELECT | |
hecode, | |
heshortcut, | |
hename, | |
concat(hename, '$', heshortcut) as newname | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND LEN(heshortcut) + 2 >= 10 | |
*/ | |
UPDATE hedocseries | |
SET hename = concat(hename, '$', heshortcut) | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND LEN(heshortcut) + 2 >= 10 | |
/* | |
3. Replace shortcut with something smaller for shortcuts that exceed the max length | |
You can always check before executing with | |
SELECT | |
hecode, | |
heshortcut, | |
concat('i-', herefnumber), | |
hename | |
FROM hedocseries | |
WHERE hename LIKE '%$%' | |
*/ | |
UPDATE hedocseries | |
SET heshortcut = concat('i-', herefnumber) | |
FROM hedocseries | |
WHERE hename LIKE '%$%' -- we have already changed the name, so only with a name containing the separator char will be replaced | |
/* | |
4. After making the Copy Series Procedure from Pylon, we replace the new code with a more relevant code | |
You can always check before executing with | |
SELECT | |
hecode, | |
replace(replace(hecode, '_#', ''),'HT-','H2-') as newcode, | |
hename | |
FROM hedocseries | |
WHERE hecode LIKE '%_#' | |
*/ | |
UPDATE hedocseries | |
SET hecode = replace(replace(hecode, '_#', ''),'HT-','H2-') | |
FROM hedocseries | |
WHERE hecode LIKE '%_#' | |
/* | |
5. Revert the name back to original | |
You can always check before executing with | |
SELECT | |
hename, | |
SUBSTRING(hename, 0, CHARINDEX('$', hename)) AS newname | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND hename LIKE '%$%' | |
*/ | |
UPDATE hedocseries | |
SET hename = SUBSTRING(hename, 0, CHARINDEX('$', hename)) | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND hename LIKE '%$%' | |
/* | |
6. Make shortcut the same as code | |
SELECT | |
heshortcut, | |
hecode, | |
hename | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND heshortcut LIKE 'i-%' | |
*/ | |
UPDATE hedocseries | |
SET heshortcut = hecode | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND heshortcut LIKE 'i-%' | |
OR heshortcut LIKE '%_#' | |
/* | |
EXTRA Revert shortcut back to original | |
SELECT | |
heshortcut, | |
SUBSTRING(hename, CHARINDEX('$', hename) + 1, LEN(hename)) AS newshortcut | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND hename LIKE '%$%' | |
*/ | |
UPDATE hedocseries | |
SET heshortcut = SUBSTRING(hename, CHARINDEX('$', hename) + 1, LEN(hename)) | |
FROM hedocseries | |
WHERE hecmbrid IS NOT NULL | |
-- AND heisusedbymodule in (2) -- enter the from the Used By Module List | |
-- AND heseriestype in (0,3,14) -- enter the value from the Series Type List | |
AND hename LIKE '%$%' | |
/* | |
Remember to DROP the backup table after completion after everything is as it should be | |
*/ | |
DROP TABLE hedocseries_bak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment