locked
Filter Data Base On Input SQL RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my table data

    Batch No ItemName
    S12-18 Mango
    S13-18 Lemon
    S14 Dates
    S15 Banana

    I need sql query

    sometime user pass S12-18 then i want to show resultset mango

    sometime user pass S12A-18  then also i want to show resultset mango

    sometime user pass S12B-18  then also i want to show resultset mango

    sometime user pass S12C-18  then also i want to show  resultset  mango

    how would be my where cluase code..

    Need help

    Thanking You

    Tuesday, July 17, 2018 10:18 AM

Answers

  • User77042963 posted
    CREATE TABLE mytable(
       Batch_No VARCHAR(6) NOT NULL  
      ,ItemName VARCHAR(6) NOT NULL
    );
    INSERT INTO mytable(Batch_No,ItemName) VALUES
     ('S12-18','Mango')
    ,('S13-18','Lemon')
    ,('S14','Dates')
    ,('S15','Banana');
    
    
    declare @p varchar(10)='S12B-18'
    Select @p = Left(@p,3)+right(@p,3)
    
    Select  * from mytable
    WHERE Batch_No=@p
    
    drop table mytable

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2018 1:37 PM

All replies

  • User-369506445 posted

    hi

    what is your mean exactly?  do you need a query that returns Batch No that include '<g data-gr-id="10" id="10" class="gr_ gr_10 gr-alert gr_gramm Style multiReplace">s12' ?</g>

     

    Tuesday, July 17, 2018 10:31 AM
  • User-492460945 posted

    Hi Gopi,

    You can do like this,

    SELECT * FROM <TABLE> WHERE BatchNo like 'S12%'

    Tuesday, July 17, 2018 10:36 AM
  • User-807418713 posted

    Hello

    I need sql query

    sometime user pass S12-18 then i want to show resultset mango

    sometime user pass S12A-18  then also i want to show resultset mango

    sometime user pass S12B-18  then also i want to show resultset mango

    sometime user pass S12C-18  then also i want to show  resultset  mango

    at any input i want to show mango record..

    Tuesday, July 17, 2018 10:49 AM
  • User-369506445 posted

    you can try below query in <g class="gr_ gr_25 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="25" data-gr-id="25">sql</g>

    declare @userSearch as nvarchar(50)
    set @userSearch = 'S12A-18'
    select * from myTable where BatchNo like '%'+SUBSTRING(@userSearch, 1, 3)+'%'

    or

    select * from myTable where BatchNo like '%'+SUBSTRING('S12A-18', 1, 3)+'%'

    Tuesday, July 17, 2018 11:04 AM
  • User77042963 posted
    CREATE TABLE mytable(
       Batch_No VARCHAR(6) NOT NULL  
      ,ItemName VARCHAR(6) NOT NULL
    );
    INSERT INTO mytable(Batch_No,ItemName) VALUES
     ('S12-18','Mango')
    ,('S13-18','Lemon')
    ,('S14','Dates')
    ,('S15','Banana');
    
    
    declare @p varchar(10)='S12B-18'
    Select @p = Left(@p,3)+right(@p,3)
    
    Select  * from mytable
    WHERE Batch_No=@p
    
    drop table mytable

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2018 1:37 PM
  • User-1716253493 posted
    SELECT * FROM YOURTABLE WHERE LEFT([batch no],3)=LEFT(@parameter,3)

    Thursday, July 19, 2018 12:25 AM