473,385 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

If Else + ...

16
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
Expand|Select|Wrap|Line Numbers
  1. Select isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'') 
  2. + '000' +
  3. Convert(varchar(10),pt_id) 
  4. + (left(ptssn,2))
  5.  
  6. as UName
  7. 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
Oct 16 '07 #1
3 1410
tmeers
16
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:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE #temptbl(
  2. pid int, RandNUmber varchar(15))
  3.  
  4. Insert into #temptbl
  5.     (pid, RandNUmber) 
  6. Select pt_id as pid, isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'') 
  7.     + '000' + Convert(varchar(10),pt_id) + isnull(left(ptssn,2),(Upper(left(ptdob,2)))) as RandNUmber
  8. from Patient
  9.  
  10. update Patient
  11. set PtRandNumber = (select #temptbl.RandNUmber from #temptbl where #temptbl.pid = Patient.Pt_id)
  12.  
  13. Drop Table #temptbl
I still need to figure out the zero's part though and thats a biggie.
Oct 16 '07 #2
iburyak
1,017 Expert 512MB
Try this:


Expand|Select|Wrap|Line Numbers
  1. Select pt_id as pid, isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'') 
  2.     + right('00000' + Convert(varchar(10),pt_id), 5) + isnull(left(ptssn,2),(Upper(left(ptdob,2)))) as RandNUmber
  3. from Patient

Good Luck.
Oct 16 '07 #3
tmeers
16
Try this:


Expand|Select|Wrap|Line Numbers
  1. Select pt_id as pid, isNull(Upper(left(PtFirstName,1)),'') + isNull(Upper(left(PtLastName,1)),'') 
  2.     + right('00000' + Convert(varchar(10),pt_id), 5) + isnull(left(ptssn,2),(Upper(left(ptdob,2)))) as RandNUmber
  3. from Patient

Good Luck.

Oh that is perfect. Thank you very much for your help.
Tim
Oct 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

33
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 -...
6
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...
27
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...
3
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...
5
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...
5
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...
4
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.*,...
8
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...
23
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...
17
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:...
1
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...
0
isladogs
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...
0
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...
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.