sql server cursor

  • omalie24 (12/14/2011)


    Yes toddasd it is….

    Sean Lange how would u have gotten it to move to the next row without a cursor

    Set based processing is paradigm shift in your thinking. You have to stop thinking about what you want to do to a row and instead think about what you want to do to a column.

    My response was intended as humor based on your comment

    ...I KNOW U WOULDNT LIKE THIS BUT I WRAPPED UR CODE IN A CURSOR AND IT WORKS...

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • lol...I didnt take ur comment any other way than which is was intended.....my question to u was b/c i was curious to know what other way i should have attacked the problem.....am trying to learn new and efficient ways of coding and ultimately thinking....

  • Hi omalie24,

    As toddsad said you really need to get your data types correct or else you will be creating problems for yourself in the very near future. And you don't need all those brackets.

    Here are a few suggestions:

    TRAN_DATE date NULL,

    TRAN_TYPE char(1) NULL,

    AVERAGE_COST money NULL,

    PRICE money NULL,

    ITEM_CODE varchar(10) NULL,

    CUST_NUMBER int NULL,

    CUSTOMER_NAME varchar(50) NULL,

    INVOICE_NUMBER int NULL,

    PO_NUMBER int NULL,

    QUANTITY int NULL

    If some of the above such as INVOICE_NUMBER is not purely numeric then it would need to be VARCHAR of appropriate length.

    Do you really want all of the columns to accept NULL value? That way you could have completely NULL rows.

    Do you have a Primary Key? If nothing unique in the existing columns then maybe add SALES_ID int identity(1,1) not null as the Primary Key.

  • Currentlty working on data types and trying to get query to run faster....its a bit slow

Viewing 4 posts - 16 through 18 (of 18 total)

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