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

    How to retrieve values by searching into comma separated values.

    Hi,

    I need to retrieve a value by searching a similar string in the database column which is having comma separated values.

    My table has the values as:

    index category keywords contentid
    1 c# encapsulation 2
    2 c# regular, expression 7


    Now i need to get contentid by matching the keyword similarity. I used the following code, It retrieves the content id if its a single keyword as encapsulation. but if i give regular it shows no rows affected and no output.


    SELECT content_id FROM tbl_index WHERE keywords LIKE @keyword;


    I need the content id 7 if i give regular or expression as input.

    Thanks..
  • #665812
    Please check the following query:


    DECLARE @keyword VARCHAR(100);
    SET @keyword = 'regular'
    SELECT contentid FROM tbl_index WHERE keywords LIKE '%' + @keyword + '%'


    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #665857
    Hai Chidambaram,

    If you have the comma separated string as your description, then first you need to get them as individual and then process with the query.
    Like for the index 2, the keywords "regular, expression" needs to be spited.
    To split, you can write a function which will take the string as the input with the delimiter to split the word from the delimiter.
    And then you can use your query.
    For the split function, you can go through the below link:"

    http://blog.logiclabz.com/sql-server/split-function-in-sql-server-to-break-comma-separated-strings-into-table.aspx

    Hope it will give you some idea of implementation.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #665891
    Thanks Paritosh....works fine :)
    With Regards,
    Chidambaram
    +91 94898 10101


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.