Hello,
could somebody help me to create query which should count number of values in column3 filtered by the values in column1 and if:
1) count exceeds e.g., 4000, create new column and split the values from column1 into 5 new values i.e., first 1000 into the same value like in column1 + character A, next 1000 into column1 + B, etc...and the remaining part into ????? + E?
2) count exceeds 3000, from A-D
3) count exceeds 2000, from A-C
4) count exceeds 1000, from A-B
Sorting should be ASC based on LastName, FirstName and FathersName?
There are approximately 10 000 distinct values in column1 and of course, if some count does not fall into one of groups, the values should be just "copy/paste" as they were found (i.e., if count does not exceed 1000). Column1 is of NVARCHAR type.
For example, if value in column1 is 001A001, and count of it exceeds 4000, in new column I need to have this:
001A001A, for the first 1000 occurencies of 001A001
001A001B for the second 1000 occurencies of 001A001
001A001C for the third 1000 occurencies of 001A001
001A001D for the forth 1000 occurencies of 001A001
001A001E for the remaining part of occurencies of 001A001
and so on for all 10000 distinct values in column1!
etc...Before splitting, there should be done sorting based on above mentioned LastName, FirstName and FathersName...
How to accomplish this like query in sql server 2008 R2?
Thanks for any code snippet that could lead me towards an solution and further fine tuning with, may be, involvement of some threshold etc..e.g., trying to keep all the LastName in the same group if the first character remains the same regardless of fact that it could lead towards exceeding of number of occurencies in some of groups (e.g., to have 1020 in the first group should be allowed).
Thanks for any assistance!
could somebody help me to create query which should count number of values in column3 filtered by the values in column1 and if:
1) count exceeds e.g., 4000, create new column and split the values from column1 into 5 new values i.e., first 1000 into the same value like in column1 + character A, next 1000 into column1 + B, etc...and the remaining part into ????? + E?
2) count exceeds 3000, from A-D
3) count exceeds 2000, from A-C
4) count exceeds 1000, from A-B
Sorting should be ASC based on LastName, FirstName and FathersName?
There are approximately 10 000 distinct values in column1 and of course, if some count does not fall into one of groups, the values should be just "copy/paste" as they were found (i.e., if count does not exceed 1000). Column1 is of NVARCHAR type.
For example, if value in column1 is 001A001, and count of it exceeds 4000, in new column I need to have this:
001A001A, for the first 1000 occurencies of 001A001
001A001B for the second 1000 occurencies of 001A001
001A001C for the third 1000 occurencies of 001A001
001A001D for the forth 1000 occurencies of 001A001
001A001E for the remaining part of occurencies of 001A001
and so on for all 10000 distinct values in column1!
etc...Before splitting, there should be done sorting based on above mentioned LastName, FirstName and FathersName...
How to accomplish this like query in sql server 2008 R2?
Thanks for any code snippet that could lead me towards an solution and further fine tuning with, may be, involvement of some threshold etc..e.g., trying to keep all the LastName in the same group if the first character remains the same regardless of fact that it could lead towards exceeding of number of occurencies in some of groups (e.g., to have 1020 in the first group should be allowed).
Thanks for any assistance!