Solved

Getting the right username

Posted on 2007-03-26
4
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
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:
Scott Pletcher 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

735 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