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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 upadate table in database from a temp table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Junior Sqler
Starting Member

18 Posts

Posted - 07/09/2013 :  11:23:30  Show Profile  Reply with Quote

I have a #temp table with 3 columns : A1, B1 and C1
and a table named Basis in databaset with 3 columns:A2, B2 and C2

I want to update tha table on database based on values of temp as following:

update Basis set

C2 = (select a.C1 from #temp where #temp.A1 =Basis.A2),

B2 =(case when (Basis.C2 <=3 and (select a.B1 from #temp3 a where #temp.A1 =Basis.A2) <= 0.05 )then 1 else 0 end)
else 1 end)

It shows: Incorrect syntax near the keyword 'else'..
Any ideas about the mistake?

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/09/2013 :  11:39:00  Show Profile  Reply with Quote
In your second statement you updating B2 based on the existing value of Basis.C2 or the value as it exists after you have performed the first update (i.e., setting C2 to the value from #temp?) The following assumes the latter:
	c2 = t.c1,
	b2 = CASE WHEN T.c1 <= 3 AND b1 < 0.05 THEN 1 ELSE 0 END 
	#temp T
	INNER JOIN Basis b ON T.A1 = b.A2;
Go to Top of Page

Junior Sqler
Starting Member

18 Posts

Posted - 07/10/2013 :  03:43:07  Show Profile  Reply with Quote
thank you!!
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.17 seconds. Powered By: Snitz Forums 2000