Ok I am trying to create a unique number for all names in a table. It's a fairly simple task but I'm having issues with it. So far I have this - Select isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'')
-
+ '000' +
-
Convert(varchar(10),pt_id)
-
+ (left(ptssn,2))
-
-
as UName
-
from Patient
But if ptssn is null it returns a null result, I was hoping to swap it with the last two digits of the person date of birth but am unable to figure it out.
Second part of my troubles are the + '000' + I want make it a 4 or 5 digit number but some of the pt_id's are already 5 digits. So if >=99 I would add 3 zero's and if >=999 I would add only 2 zeros and if >=9999 I would add only 1 zero. Anything above 9999 would be fine as it is. I tried using a CASE to do it but cannot figure it out.
Hoping some one has a quick solution to this issue.
Tim
3 1410
Well I got part of it figure out and I figured out how to update the already existing table. Here's what I have so far: - CREATE TABLE #temptbl(
-
pid int, RandNUmber varchar(15))
-
-
Insert into #temptbl
-
(pid, RandNUmber)
-
Select pt_id as pid, isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'')
-
+ '000' + Convert(varchar(10),pt_id) + isnull(left(ptssn,2),(Upper(left(ptdob,2)))) as RandNUmber
-
from Patient
-
-
update Patient
-
set PtRandNumber = (select #temptbl.RandNUmber from #temptbl where #temptbl.pid = Patient.Pt_id)
-
-
Drop Table #temptbl
I still need to figure out the zero's part though and thats a biggie.
Try this: - Select pt_id as pid, isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'')
-
+ right('00000' + Convert(varchar(10),pt_id), 5) + isnull(left(ptssn,2),(Upper(left(ptdob,2)))) as RandNUmber
-
from Patient
Good Luck.
Try this: - Select pt_id as pid, isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'')
-
+ right('00000' + Convert(varchar(10),pt_id), 5) + isnull(left(ptssn,2),(Upper(left(ptdob,2)))) as RandNUmber
-
from Patient
Good Luck.
Oh that is perfect. Thank you very much for your help.
Tim
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Diez B. Roggisch |
last post by:
Hi,
today I rummaged through the language spec to see whats in the for ... else:
for me. I was sort of disappointed to learn that the else clauses simply
gets executed after the loop-body -...
|
by: Christian Seberino |
last post by:
I am looking at the ELSE home page and trying to figure out if I should
invest the time to learn about the ELSE minor mode for Emacs.
Is there any programmer out there using ELSE that is getting...
|
by: Ron Adam |
last post by:
There seems to be a fair amount of discussion concerning flow control
enhancements lately. with, do and dowhile, case, etc... So here's my
flow control suggestion. ;-)
It occurred to me (a...
|
by: Patrice |
last post by:
Hi,
I need to do multi-conditional statements like below, but this error is
displayed :
Expected 'End'
/myFilepath, line x
else response.write(arrCorpo(sparam,sdiv)) end if
I don't...
|
by: WindAndWaves |
last post by:
Hi Team
The function below searches all the tables in a database. However, if
subsearch = true then it searches all the objects listed in a recordset
(which are all table names).
I thought to...
|
by: Brie_Manakul |
last post by:
Is there a way in javascript to do an if else that shows a script in an
iframe? Let me know if that doesn't make sense. We have a portal and
in a portlet I need to grab these javascript links to...
|
by: Brie_Manakul |
last post by:
I need to set up an if else to show different weather scripts based on
the city selection they choose. Any help on this would be great.
Thanks!
<%@ page language="java" import="java.util.*,...
|
by: pelicanstuff |
last post by:
Hi - Was wondering if anybody could tell me why this rather crappy code is giving me an 'Else without If' error on compile?
All the Elses and Ifs look ok to me but there's a few.
Private Sub...
|
by: bearophileHUGS |
last post by:
So far in Python I've almost hated the 'else' of the 'for' loops:
- I have problems to remember its meaning;
- It gives me little problems when I later want to translate Python
code to other...
|
by: JRough |
last post by:
I'm trying to get error proof code.
I have this code which seems to work but now I look at it I think it
should be elseif not else and I wonder why it works. It is in the
block:...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |