Home Forums SQL Server 2012 SQL 2012 - General make over columns using comma seperated and select in query RE: make over columns using comma seperated and select in query

  • drew.allen (9/28/2016)


    mcfarlandparkway (9/28/2016)


    TY for the response, In the recent code we are selecting data form temp table where DOC NOT IN (select DOC from table where code<> -1)

    This is what the same we are trying to implement here. DOC will replace with all these 3 columns(emp1,emp2 and emp3)

    That's why I tried to separate with comma and again select those columns in the query.

    Structure should be same..

    that's why I tried select * from Employee where (emp1,emp2,emp3) IN (select emp1,emp2,emp3 from employee)

    In the where clause I can use the code which you provided to CAST in the select statement looks good to me.

    No, they should not be the same. One is a single column, the other is a list of columns. Those are not the same structures any more than an integer is the same structure as an array of integers.

    Drew

    Very much this. You can't simply refer to the columns and they'll magically get combined. You have to combine them. Minimum would be to use the plus (+) sign between them. Strings should naturally concatenate that way. However, that is going to lead to a tuning nightmare to filter on combined columns means no index use or statistics use.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning