You must Sign In to post a response.
  • Category: SQL Server

    Get common saleids data with latest date

    I have a table

    Ids | Saleids | Datemodified | datecreated
    121 |909 |404|505 | 1th april 2016 | 3rd april 2016
    122 |809 | 2th april 2016 | 3rd april 2016
    123 |404|708 | 4th april 2016 | 3rd april 2016
    124 |689 | 4th april 2016 | 3rd april 2016

    If @saleid=404,
    @id=121

    Then:


    Result:
    Ids | Saleids | Datemodified | datecreated

    121 |404 | 4th april 2016 | 3rd april 2016
  • #765359
    Hi niketa,
    Please run following script in SQL query window:
    create table #sales (Ids numeric, Saleids varchar(100), Datemodified datetime, datecreated datetime )
    Insert into #sales (Ids, Saleids ,Datemodified ,datecreated )
    values (121,'909 |404|505', '2016-04-01 12:40:46.500', '2016-04-03 12:40:46.500' ),
    (122,'809', '2016-04-02 12:40:46.500', '2016-04-03 12:40:46.500'),
    (123,'404|708', '2016-04-04 12:40:46.500', '2016-04-03 12:40:46.500'),
    (124,'689', '2016-04-04 12:40:46.500', '2016-04-03 12:40:46.500')
    select * from #sales
    select Ids, Saleids, Datemodified = (select MAX(Datemodified) from #sales where Saleids like '%404%' ), datecreated from #sales where Saleids like '%404%' and Ids=121
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #765374
    Hi,

    I'm little bit confused about your required output, request you to please provide few more details to provide some what better solution.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments