Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 no cursor

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-05-20 : 10:08:01
I have a table look like

pat_id last first Bill_last Bill_first
101 john smith john smith
89 kathy smith john smith
111 David martin david martin
345 john patrick john patrick
456 sandy partick john patrick

I would like to add a column called "bill_pat_id": the patient_id of a person who will be responsible for the bill.


pat_id last first Bill_last Bill_first bill_pat_id
101 john smith john smith 101
89 kathy smith john smith 101
111 David martin david martin 111
345 john patrick john patrick 345
456 sandy partick john patrick 456

I am trying to find a way to do this without using a cursor...




Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-05-20 : 10:25:50
[code]
Select
A.pat_id,
A.last,
A.first,
A.bill_last,
A.bill_first,
bill_pat_id = B.pat_id
from yourTable A
Inner Join yourTable B
on A.bill_last = B.last
and A.bill_first = B.first
[/code]

By the way, I do NOT recommend having to join on names. What happens if you have two john smiths?? does one of them get stuck with all the bills while the other gets free service?

Corey

Secret Service Agent: Mr. President, you're urinating on me.
President Lyndon Johnson: I know I am. It's my prerogative.
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-05-20 : 10:40:47
That would be a really bad idea in a hospital or clinic environment where you have hundreds or thousands of patients. It would probably be a quick way to get fired.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-05-20 : 15:27:21
Hey, maybe last + first name is a unique index !

rockmoose
Go to Top of Page
   

- Advertisement -