SELECT OR CURSOR

  • 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?

  • 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

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • So you don't need to use cursor!

    🙂

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply