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

    Row value as column name

    DECLARE @ISBN varchar(20) = 'a,bbbb,ccc,ddd,ee'


    I have string with commas like above.
    I need this each value as column name like :

    a bbbb ccc ddd ee
  • #768853
    Hi lily,

    As per my understanding you want dynamic sql query right?

    Use below sample to achieve your thing


    DECLARE @ISBN varchar(20) = 'a,bbbb,ccc,ddd,ee'

    SET @ISBN='SELECT ' +@ISBN+ ' from yourtablename';

    Execute @ISBN;


    you have to remember before execute you have to recheck the query by using PRINT statement, the print statement query should be execute without any issues then only your query is correct.

    Hope this helps you....

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments