Get column header from a table value

  • I have two tables

    Cst (for customers) and

    Prd (for Products):

    I will display the values of Product Code (PrdCode) with column title the 'CstFullName' that I get from Cst (Customers):

    ===================================================================

    declare @S1 varchar(512)

    declare @S2 varchar(255)

    Select @s1 = c.name

    from sysobjects o, syscolumns c

    where o.id = c.id and o.type='U' and o.name='Cst' and c.name='CstFullName'

    select @s2= 'select prdCode as '+ @s1+' from prd'

    exec(@s2)

    ========================================================

    The above is a workaround that I hope it will help you!

    AJV

    PS: Kali sinexeia, elpizw na min 8es na ksegelaseis kanena me ayto to query... 😉

    ------------
    When you 've got a hammer, everything starts to look like a nail...

  •  

    I think your Question is not properly justified,

    It may be happen but i have no words to explain it ??

     

    sorry

     

  • Amit you are right.

    Andreas solution has the effect of returning the column name to the query string, when I was looking for a value in the table.

    However, his approach, that is, to build up a querystring is what I was looking for. So I merely adjusted the code to fetch the relevant field from the table rather than the actual column name.

    It works fine.

    Thanks Andreas (poli orea )

Viewing 3 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply