December 30, 2010 at 12:22 am
CREATE TABLE #TAB1 (SNO INT ,DEPTID INT,DEPTNAME VARCHAR(50))
CREATE TABLE #TAB2 (SNO INT,DEPTID INT)
CREATE TABLE #TAB3 (DEPTID INT,DEPTNAME VARCHAR(50))
INSERT INTO #TAB2 VALUES(1,10)
INSERT INTO #TAB2 VALUES(1,20)
INSERT INTO #TAB2 VALUES(2,30)
INSERT INTO #TAB2 VALUES(2,10)
INSERT INTO #TAB3 VALUES(10,'COMPUTER')
INSERT INTO #TAB3 VALUES(20,'MATHS')
INSERT INTO #TAB3 VALUES(10,'SCIENCE')
---------------------------------------------------><------------
I NEED TO INSERT THE VALUES OF TAB2 AND TAB3 INTO TAB1... IS POSSIBLE USING INSERT INTO TAB1 SELECT COMMAND OR SHOULD I USE CURSOR FOR THIS?
December 30, 2010 at 1:27 am
One alternative is:
INSERT INTO #TAB1
SELECT T2.SNO, T3.DEPTID, T3.DEPTNAME
FROM #TAB2 T2 INNER JOIN #TAB3 T3 ON T2.DEPTID = T3.DEPTID
December 30, 2010 at 1:36 am
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply