sqlquery

  • Hi..

    1) I want to fetch the 4th highest record from a table.

    2) I want to write a storedProc for inserting values from one table(like ADMISSIONFORM) to two table (like student & studentdet). From the two table STUDENT is Master Table And studentdet is Detail table. When we insert the values from Admissionform to Student (some fields) there is one primeryKey like STUDENTID. Now we have to insert values in the STUDENTDET table(some fields) for that particular STUDENTID.

    There are thousands of record in the admissionform.

    Please help me to write the storproc.

    thanx & regards

    Sonmani Sharma

  • FINDING 4TH HIGHEST SALARY:-

    CREATE TABLE SALARY (ID BIGINT,SALARY BIGINT)

    GO

    INSERT INTO SALARY (ID,SALARY) VALUES (1,200)

    INSERT INTO SALARY (ID,SALARY) VALUES (2,300)

    INSERT INTO SALARY (ID,SALARY) VALUES (3,400)

    INSERT INTO SALARY (ID,SALARY) VALUES (4,500)

    INSERT INTO SALARY (ID,SALARY) VALUES (5,600)

    SELECT TOP 1 * FROM

    (SELECT TOP 4 * FROM SALARY ORDER BY SALARY DESC)A

    ORDER BY SALARY ASC

  • Fourth highest record by what? Please post the table definitions and some sample data. The same comment applies to the 2nd part of your question. Without more info I can't answer.

    If you're using SQL 2005, the ROW_Number is good for getting the nth row ordered by some column.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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