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

    Matching uids from Comma separated in the same table

    Hi Everyone,

    This s my table,This needs kind of self join but we have tow uids in the comma separated column.

    Store

    UID RequestStoreUID Code
    1 85,63 BHLB
    85 4 BHLR
    63 NULL BHEW
    2 NULL BHIP
    3 NULL BHPS
    4 NULL BHOT

    I need to get below output if i pass 1 in where condition

    UID RequestStoreUID Code
    1 85,63 BHLB
    85 4 BHLR
    63 NULL BHEW
  • #768257
    Hi,
    Can you please elaborate your question in detail?
    because it seems difficult for me to understand.
    Your UID column from first row contains value = 1 85,65 i.e. UID1= 185 and UID2=65. Is it correct?

  • #768288
    you can use given command for Comma separated in the same table
    select * from users WHERE id = 2 OR FIND_IN_SET(id,(select UID from users where id = 2))

  • #768291
    I think you need to first get the rows database for specified id, (in your case its 1) then try to fetch the row values and then split them with ',' (comma) and finally Join the result
    To execute this process you need a SPLIT and JOIN query, see below syntax
    if you are using SQL 2016 then there is inbuilt function for split 'STRING_SPLIT ' you can use.
    other wise check below url
    http://www.aspsnippets.com/Articles/Split-function-in-SQL-Server-Example-Function-to-Split-Comma-separated-Delimited-string-in-SQL-Server-2005-2008-and-2012.aspx

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments