Loop Thru a Table

  • Dear Sir,

    I have a Table given below in SQL DB & want to go record by record (Alive to Vinit) to these Table . How can I do ?

    Employee ID Basic Salary Joining Date

    Alive 10000 01/04/2009

    Neel 20000 01/04/2010

    Vinit 30000 1/04/2011

    I want to do some process for every single record that's why I want to go row by row.How to achieve that ?

    Kindly reply.

  • Im afraid that your question exposes the fact that you dont understand what an RDBMS is at a rather fundemental level.

    You should not be thinking about going row-by-row.

    Try this book

    http://www.amazon.co.uk/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905/ref=sr_1_1?ie=UTF8&s=books&qid=1306578661&sr=8-1



    Clear Sky SQL
    My Blog[/url]

  • I have a Temporary Table which has no of records (Rows) Now I want to go these Temp Table thru row by row. Is it Possible in SQL ???

  • subrata.bauri-1051938 (5/29/2011)


    I have a Temporary Table which has no of records (Rows) Now I want to go these Temp Table thru row by row. Is it Possible in SQL ???

    Please explain why you insist in dealing with one row at a time. What's the business case forcing it?



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • I'm designing a report which will give Production BOM Details Where I feel this requirement.

  • In SQL you should almost never iterate row-by-row. Nothing you've said so far indicates there's any need to do operations on individual rows.

    What exactly are you trying to do?

    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
  • Please provide table def and sample data in a ready to use format as described in the first link in my signature together with your expected result.

    I'm confident there's a set based solution available. Also,please confirm you're using SQL2000 or SQL7 as indicated by the forum you posted in.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • BPD & BPD001,BPD002,BPD003 has a relation.

    BPD001 has relation with its child(BPDX01) Item but BPD has no direct relation to BPDX01...

    Input parameter id BPD

    Output are BPDX01, etc as shown in picture.

  • Not clear.

    Please post table definitions, sample data and expected results as per http://www.sqlservercentral.com/articles/Best+Practices/61537/

    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
  • Maybe you could show us the code that you have achieved so far yourself ? That would help us in the best way to advise you.



    Clear Sky SQL
    My Blog[/url]

  • Suppose in a certain Table I have all the required data. Item Code is a field of this table.

    Item--- BPD (finished Good)has three child Items BPD01, BPD02, BPD03 and

    BPD01 has tree child Item -- BPDX01, Qty-3

    BPDX02, Qty-5

    BPDX03, Qty-2

    BPD02 has tree child Item -- BPDX04, Qty-1

    BPDX02, Qty-4

    BPDX01, Qty-2

    BPD02 has tree child Item -- BPDX03, Qty-6

    BPDX04, Qty-5

    BPDX01, Qty-6

    Some one give the input --BPD and Output will be

    Item Code Qty

    BPDX01 11

    BPDX02 9

    BPDX03 8

    BPDX04 6

    BPD & BPD001,BPD002,BPD003 has a relation.

    BPD001 has relation with its child(BPDX01) Item but BPD has no direct relation to BPDX01...

  • kindly reply

  • Please post table definitions, sample data and expected results as per http://www.sqlservercentral.com/articles/Best+Practices/61537/

    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
  • GilaMonster (5/30/2011)


    Please post table definitions, sample data and expected results as per http://www.sqlservercentral.com/articles/Best+Practices/61537/

    This appears to be easily solved with:

    SELECT [Item Code], Qty = COUNT(*)

    FROM [a Certain Table]

    GROUP BY [Item Code]

    ORDER BY [Item Code]

    If this isn't quite what you're looking for, then remember that the people that help out here are all un-paid volunteers, so please HELP US HELP YOU. Providing the DDL scripts (CREATE TABLE, CREATE INDEX, etc.) for the tables affected, and INSERT statements to put some test data into those tables that shows your problem will go a long way in getting people to look at your issue and help you out. Please include code for what you have already tried. Don't forget to include what your expected results should be, based on the sample data provided. As a bonus to you, you will get tested code back. For more details on how to get all of this into your post, please look at the first link in my signature - Which just happens to be the same link that Gail has pointed you to twice now.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • subrata.bauri-1051938 (5/30/2011)


    kindly reply

    Please note that we are all volunteers and we're not spending each and every minute waiting to reply on a post. Asking for an answer just 15 minutes after your latest post seems demanding... You might have increased the chances for an answer if you would actually have followed the advice given by Gail and myself (asking for some ready to use sample data).

    Unfortunately, we still don't have anything to work with.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 15 posts - 1 through 15 (of 30 total)

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