Hi all,
I am facing an issue on which I really appreciate some advices.
Here is the thing:
I have a table called Companies which is like this:
Id Name
55 Foo Corp
56 Ku Corp
I have an other table referencing the Users:
Id CompanyId Name
1 55 John
2 56 Marc
3 55 Michael
4 55 Terry
5 56 Dorcel
What I need is to be able to compute the Id of the Users based on the Company Id
For Example I would like to have:
CustomId
C55U1 (Company 55 User 1) John
C56U1 Marc
C55U2 Michael
C55U3 Terry
C56U2 Dorcel
(I just need the User index relative to its own company as I can get the rest using a computed column specification)
I want to do that because the users id are exposed to the users and using the Native incremental (+1) id will expose to someone the number of created user by the other companies since he last created an user.
I would like to avoid having to do a COUNT query in case several users are created in the same time and this might not be very efficient.
The only reliable solution I can think of is to create a user table for each company but I think they might be a smarter solution but my knowledge of SQL is limited. This is why I ask for your help :)
Thanks a lot.
I am facing an issue on which I really appreciate some advices.
Here is the thing:
I have a table called Companies which is like this:
Id Name
55 Foo Corp
56 Ku Corp
I have an other table referencing the Users:
Id CompanyId Name
1 55 John
2 56 Marc
3 55 Michael
4 55 Terry
5 56 Dorcel
What I need is to be able to compute the Id of the Users based on the Company Id
For Example I would like to have:
CustomId
C55U1 (Company 55 User 1) John
C56U1 Marc
C55U2 Michael
C55U3 Terry
C56U2 Dorcel
(I just need the User index relative to its own company as I can get the rest using a computed column specification)
I want to do that because the users id are exposed to the users and using the Native incremental (+1) id will expose to someone the number of created user by the other companies since he last created an user.
I would like to avoid having to do a COUNT query in case several users are created in the same time and this might not be very efficient.
The only reliable solution I can think of is to create a user table for each company but I think they might be a smarter solution but my knowledge of SQL is limited. This is why I ask for your help :)
Thanks a lot.
Comment