Solved

Getting the right username

Posted on 2007-03-26
4
215 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
ID: 18795056
What if you  have "Sarah Parker" and "Sam Parker"?
0
 

Author Comment

by:DancingFighterG
ID: 18796002
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
ID: 18796130
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
ID: 18797348
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

911 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

20 Experts available now in Live!

Get 1:1 Help Now