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)
 SQL query onn multiple values

Author  Topic 

sqlpal2009
Yak Posting Veteran

58 Posts

Posted - 2009-03-31 : 09:40:38
Hello All,

I am writing insert statement which should insert records in table1 from two tables table2 n 3.

Table2 has TranCode column as int values are (0,1,2,3) and Table3 has the same column but is defined as varchar type and the values are (Comppleted, Rejected, InTransit, Failed) The Table2 and Table3 relate with each other by Trancode and TranNo. The TranNo is same in both the tables and have more than one row for each tranNo (compositekey on TranCode and TranNo) but the TranCode is different as 0 - Completed, 1 - Rejected and so on)

I wanted to insert Trancode from Table2 and get rest of the information from Table3 where tranNo matches and the TranCode maps correctly.

I thought of doing it in multiple update statements for Table3 once inserted the data from Table2.

Is there a way to achieve this in one insert/update?

Thanks,
-S

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-31 : 09:55:54
Probably.
See http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -