?
Solved

Getting the right username

Posted on 2007-03-26
4
Medium Priority
?
266 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 500 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

764 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