Solved

Getting the right username

Posted on 2007-03-26
4
202 Views
Last Modified: 2008-02-01
Ok, thanks to all of you the update works fine. My last problem with this SP is that the store procedure does not accomondate for names that the same first intial and same last name. So for example say you have Sarah Parker and Scott Parker. When I use the SP there will be two sparker. Now in the SP the username that will be put in as a paramete will be sparker or saparker. How do I get it where the SP will look for a 2 character in the name if the previous name already exist? In the end every username HAS to be unique. Here is the query right now:

UPDATE dbo.Users
SET userstat = 'I'
FROM dbo.Users
INNER JOIN dbo.Contact ON dbo.Users.UserCntctID = dbo.Contact.CntctID
WHERE dbo.Users.UserStat = 'A' AND dbo.Users.UserDBMnkr NOT IN ('sysuser', 'RAMQ', 'RAMQ2')
AND LOWER(LEFT(dbo.Contact.CntctFrstNme, 1) + dbo.Contact.CntctLstNme) = 'gmahoney'
0
Comment
Question by:DancingFighterG
  • 2
  • 2
4 Comments
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
What if you  have "Sarah Parker" and "Sam Parker"?
0
 

Author Comment

by:DancingFighterG
Comment Utility
I didn't think about that senario. So I guess I just need a better solution overall to doing this? Any ideas?
0
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 125 total points
Comment Utility
For the initial assignment, i.e. INSERT, of the new id, you could check for the existence of *every* possible valid combination and pick the *shortest* one.  I can provide code for that if you like.

But when doing a lookup / update, you will have to pass in the specific userid and/or the full name (full name will always work unless you have two, say, John Smith's working there).

The computer by itself can't know from userid "sparker" alone whether that relates to Sarah or Scott.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Ok, well right now and need a solution for lookup and update. Changing how data is inserted is not possible right now. What if I do something like this. Is there anyway to run some type of conditional statements (which I doubt in sql) that will allow me to say "if duplicate names exist find a unique letter to make the name unique" Usually things like this are done with CF or other languages but maybe there is something with sql that I don't know!! If not then I guess this not possible with the current setup of my system.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now