How identify the last inserted values in select query

  • Hi guys,

    How to identify the last inserted values in "select Query"

    Example Query :

    select * from iPROMIS_BI_FLOW_LINEUP where FLOW_LINEUP_NAME like '%2CUF%' order by FLOW_LINEUP_NAME asc

    Thanks

    Ranganathan palanisamy

  • ranganathanmca (7/20/2012)


    Hi guys,

    How to identify the last inserted values in "select Query"

    Example Query :

    select * from iPROMIS_BI_FLOW_LINEUP where FLOW_LINEUP_NAME like '%2CUF%' order by FLOW_LINEUP_NAME asc

    Thanks

    Ranganathan palanisamy

    Not enough information to give you answer. If you have a DateCreated column, that would help. Also an identity column could be used, unless of course it were reseeded to a lower value. You could also look at other datetime columns, they may help identify the newest record in the result set.

  • thanks for your anwser

    please find the table structre

    Column

    FLOW_LINEUP_ID

    FLOW_LINEUP_NAME

    FLOW_LINEUP_DESC

    METER_ID

    FLOW_LINEUP_ACT_CALCNAME_ID

    FLOW_LINEUP_ACTUAL_CALCTYPE

    SIMTO_TAG_ID

    FLOW_LINEUP_SIMTO_CALCNAME_ID

    FLOW_LINEUP_PLAN_CALCTYPE

    FLOW_LINEUP_FLAG

    FLOW_LINEUP_CR_DT

    FLOW_LINEUP_MD_DT

    FLOW_ID

    datatype :

    int

    varchar

    varchar

    int

    int

    char

    int

    int

    char

    varchar

    datetime

    datetime

    int

  • ranganathanmca (7/20/2012)


    thanks for your anwser

    please find the table structre

    Column

    FLOW_LINEUP_ID

    FLOW_LINEUP_NAME

    FLOW_LINEUP_DESC

    METER_ID

    FLOW_LINEUP_ACT_CALCNAME_ID

    FLOW_LINEUP_ACTUAL_CALCTYPE

    SIMTO_TAG_ID

    FLOW_LINEUP_SIMTO_CALCNAME_ID

    FLOW_LINEUP_PLAN_CALCTYPE

    FLOW_LINEUP_FLAG

    FLOW_LINEUP_CR_DT

    FLOW_LINEUP_MD_DT

    FLOW_ID

    datatype :

    int

    varchar

    varchar

    int

    int

    char

    int

    int

    char

    varchar

    datetime

    datetime

    int

    Doesn't tell me a thing. I don't know what the table is nor do I know what or how the data gets into the table. These are things you know and you need to use that knowledge to determine what the answer to your question happens to be.

    A guess would be one of these two columns:

    FLOW_LINEUP_CR_DT

    FLOW_LINEUP_MD_DT

  • sorry it my mistake not mention column desciption,

    FLOW_LINEUP_CR_DT -> while insert datetime

    FLOW_LINEUP_MD_DT --> Modified insert datetime

    Thanks for you reply...

    Thanks

    Ranganathan palanisamy

  • Looks to me that you have enough information to answer your own question at this time.

  • Thanks for your support

    i found the solution

    find below query

    select MAX(FLOW_LINEUP_NAME) from iPROMIS_BI_FLOW_LINEUP where FLOW_LINEUP_NAME like '%2CUF%'

  • OUPUT Clause after a dml statement also gives the latest updated/inserted/deleted rows. Check this link for more details:

    msdn.microsoft.com/en-us/library/ms177564.aspx

    Lokesh

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • lokeshvij (7/22/2012)


    OUPUT Clause after a dml statement also gives the latest updated/inserted/deleted rows. Check this link for more details:

    msdn.microsoft.com/en-us/library/ms177564.aspx

    Lokesh

    True enough but that won't work if you're trying to find the "last inserted" rows after the fact.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • ranganathanmca (7/20/2012)


    Thanks for your support

    i found the solution

    find below query

    select MAX(FLOW_LINEUP_NAME) from iPROMIS_BI_FLOW_LINEUP where FLOW_LINEUP_NAME like '%2CUF%'

    How does a name like FLOW_LINEUP_NAME identify the "last inserted" information? Is the name based on a date or something similar?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 10 posts - 1 through 9 (of 9 total)

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