locked
Fetch Data From Given Input RRS feed

  • Question

  • User2033107836 posted

    Hello
    Table 1 Data

    Field1	Field2	Filed3
    Apple	50	01-Oct-2017
    Mango	60	02-Oct-2017
    Banana	10	02-Oct-2017
    Mango	60	03-Oct-2017

    User will pass like this 01-Oct-2017,02-Oct-2017 

    I want to show this data

    Field1	Field2	Filed3
    Apple	50	01-Oct-2017
    Mango	60	02-Oct-2017
    Banana	10	02-Oct-2017

    how to do so 

    Note : Field3 data type is : datetime

    Tuesday, October 31, 2017 7:07 PM

Answers

  • User2103319870 posted

    You could create a function like the one mentioned in this article which will convert the comma separated values in to a table result set. You can call this function in your query like below

    DECLARE @str VARCHAR(MAX)
    SELECT @str=' 01-Oct-2017,02-Oct-2017'
    
    SELECT [Field1]
          ,[Field2]
          ,[Field3]
    FROM YourTable WHERE [Field3] IN(  SELECT Item FROM dbo.SplitString(@str, ','))
             

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 31, 2017 7:57 PM

All replies

  • User2103319870 posted

    You could create a function like the one mentioned in this article which will convert the comma separated values in to a table result set. You can call this function in your query like below

    DECLARE @str VARCHAR(MAX)
    SELECT @str=' 01-Oct-2017,02-Oct-2017'
    
    SELECT [Field1]
          ,[Field2]
          ,[Field3]
    FROM YourTable WHERE [Field3] IN(  SELECT Item FROM dbo.SplitString(@str, ','))
             

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 31, 2017 7:57 PM
  • User347430248 posted

    Hi asp.ambur,

    as I already suggested in other thread.

    How To Get resultset based on comma value

    you can use same query with little bit changes.

    Table:

    Query:

    SELECT * 
    FROM Table_2 
    WHERE f3 in ('2017-10-01','2017-10-02');

    Output:

    Regards

    Deepak
      

    Wednesday, November 1, 2017 1:59 AM