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 2005 Forums
 Transact-SQL (2005)
 query required

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-07-08 : 09:30:22
Hi this is my oracle query can anyone help me out in giving it in sql server.

Update EMRPATIENTSMASTER_bak a Set Race_id = (Select Race_Ethnicity_id From

(Select Patient_id, Min(Race_Ethnicity_id) as Race_Ethnicity_id from EMRPATIENTRACEETHNICITY_bak

Group by Patient_id Order by Patient_id) b

Where b.Patient_id = a.Patient_id)


madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-08 : 09:49:05

try this

Update a
Set Race_id = b.Race_Ethnicity_id
from EMRPATIENTSMASTER_bak as a inner join
(
Select Patient_id, Min(Race_Ethnicity_id) as Race_Ethnicity_id from EMRPATIENTRACEETHNICITY_bak
Group by Patient_id Order by Patient_id
) b
on b.Patient_id = a.Patient_id



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-08 : 09:50:04
Try this:

update a
set Race_id = b.Race_Ethnicity_id
from EMRPATIENTSMASTER_bak a
join
(Select Patient_id, Min(Race_Ethnicity_id) as Race_Ethnicity_id
from EMRPATIENTRACEETHNICITY_bak
Group by Patient_id) b
on b.Patient_id = a.Patient_id



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-08 : 09:51:22
Oh no!
Again toooooooooooo late!

But mine is without that ORDER BY


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-07-08 : 09:52:08
seperated at birth? word to word same query :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-08 : 09:58:31
Yes - seems like we are akind of twins but madhi is a bit faster


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-08 : 10:06:13
quote:
Originally posted by webfred

Oh no!
Again toooooooooooo late!

But mine is without that ORDER BY


No, you're never too old to Yak'n'Roll if you're too young to die.


Order by is not needed. It was due to copy/paste

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-08 : 10:06:42
quote:
Originally posted by rohitkumar

seperated at birth? word to word same query :)


It happens sometimes

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -