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)
 Moving data from TableA to TableB conditional

Author  Topic 

milgurung@hotmail.com
Starting Member

3 Posts

Posted - 2008-11-14 : 09:38:58
Hi all,

Could you please help me to move data from one table to another? It's a bit tricky.
a. Table A has 2 colums
1.map 2. Amount
B. Table B has 3 columns
1. TAmount 2. GAmount 3. PAmount

Now depeding upon the value of "map" column, data needs to be moved to either TAmount or GAmount or PAmount.

e.g if "map" = T then TAmount columns is filled and rest are null
if "map" = G then GAmount columns is filled and rest are null/empty


Any suggestion is appriciated? I am looking a solution based on

INSERT INTO TableB(TAmount,GAmount,PAmount)
SELECT
....
FROM
TableA


Thanks.

Sim.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-14 : 10:12:57
INSERT TableB (tAmount, gAmount, pAmount)
SELECT CASE WHEN map = 't' then amount ELSE NULL END,
CASE WHEN map = 'g' then amount ELSE NULL END,
NULL
FROM TableA



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

- Advertisement -