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

    How to split commas in where condition

    Column1. Column2
    Row1 value1
    Row2. Value2,value1
    Row3 value1, value3,value2

    Hi,

    I need to achieve a sql query.
    Condition1 : Column2 should come in 'where' condition'.
    Condition2 : In case of two or three or more value(with splitted by commas), it should automatically come in 'where' condition divided by 'or'

    Example:

    select * from tablenamr where (case when column1=row3
    Then column2=value1 or column2=value3 or column2=value2)
  • #768138
    string a= "monday,tuesday,thursday"

    Now, I am passing this value to a stored procedure as a string. I want to fire query like:
    Select *
    from tablename
    where days = 'monday' or days = 'tuesday' or days = 'thursday'`

  • #768139
    Hi Lily,

    Why not we can use IN Clause for your problem. Because instead of OR, IN clause also gave the same result for your problem.


    Select * from Tablename where days IN ('monday','tuesday','wednesday')


    So if any one is true in the list your select query will be displayed.

    Kindly write the query with IN clause and check in SQL Server whether you are getting the same result as you are expecting.

    Thanks,
    Mani


Sign In to post your comments