SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Update Query with Case inner join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kashif.special2005
Starting Member

India
10 Posts

Posted - 06/19/2012 :  08:01:13  Show Profile  Reply with Quote
Hi,

I want to update a Table1.class column with Table2 tables data with inner join with condition that
When age<=10 then 2 else 2, and I am using below query but it is giving me an error message that

update Table1
set class=
case
t.age <= 10 then 2
else
3
end
from Table1 v inner join Table2 t on v.id=t.id

Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near '<'.

Table 1
id subject class
100 B NULL
100 E NULL
100 R NULL
101 R NULL
101 K NULL
101 A NULL
102 Z NULL
102 L NULL
102 N NULL
102 O NULL

Table 2
id age
100 10
101 15
102 8


Please help to resolve this problem.

Thanks
Kashif

matty
Posting Yak Master

161 Posts

Posted - 06/19/2012 :  08:05:04  Show Profile  Reply with Quote

update v
set class= case WHEN t.age <= 10 then 2 
				else 3
		   end
from Table1 v 
inner join Table2 t 
on v.id=t.id
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 06/19/2012 :  08:06:07  Show Profile  Visit webfred's Homepage  Reply with Quote

CASE
WHEN ... THEN
ELSE
END


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

Edited by - webfred on 06/19/2012 08:07:00
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000