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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating with correlated subqueries
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 09/30/2012 :  06:21:43  Show Profile  Reply with Quote
I have a table call CaseTypeCode with 2 columns: typeCode and caseType. Assuming that the CaseTypeCode table has been populated with all possible case types and each case type has been assigned a type code, replace the column caseType in the Case table with a new column typeCode. Add the correct type into the existing rows in the Case table to refer to the corresponding typeCode given the caseType of the case.

I have created a new column caseType in Case table, but it's now filled with NULL. I need to fill them with the caseType from CaseTypeCode. A subquery like below won't work because the subquery result in multiple output. I think I need a correlated subquery.

update [Case]
set [Case].typeCode = 
	(select ctc.caseType
	from [CaseTypeCode] as ctc
	where ctc.caseType=[Case].caseType);

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/01/2012 :  10:52:40  Show Profile  Reply with Quote

SET c.typeCode=cc.TypeCode
FROM Case c
INNER JOIN CaseTypeCode cc
ON cc.caseType = c.caseType

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000