none
How to Get Query's metadata? RRS feed

  • Question

  • Hi guys
    I use a SqlDataReader to get schema information for a query. It works fine but there is a problem if I use two instances of one table in my query and use table alias to distinguish them, the schema table returned by reader doesn't have any information about table aliases. Is there any way to get table aliases for a query. Or is there any other way to get meta data for a query?

    Thanks
    Sunday, October 11, 2009 6:53 AM

Answers

  • Hi Mehdi58,

     

    Since sql server doesn’t provide the aliases to the dataset, you can write it in the column name, for example,

    SELECT s1.id as [s1.id] from stu s1 join stu s2 on s1.id = s2.id

     

    Does this work for you? If you have any questions or concerns, please update the thread and we will have a further discussion.

     

     

    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Friday, October 16, 2009 1:47 AM
    Tuesday, October 13, 2009 10:20 AM

All replies

  • Hi Mehdi58,

     

    Since sql server doesn’t provide the aliases to the dataset, you can write it in the column name, for example,

    SELECT s1.id as [s1.id] from stu s1 join stu s2 on s1.id = s2.id

     

    Does this work for you? If you have any questions or concerns, please update the thread and we will have a further discussion.

     

     

    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Friday, October 16, 2009 1:47 AM
    Tuesday, October 13, 2009 10:20 AM
  • Hi

    That's helpful but my queries are dynamic and I cant assume that alias is coded in column name.
    Saturday, October 17, 2009 6:05 AM
  • Hi Mehdi,

     

    Could you describe a scenario that you should get the table aliases?

    Maybe we could make it out in other way.

     

     

    Thanks!

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Sunday, October 18, 2009 7:55 AM
  • Yes very Nice Question.

    I actually want to filter results to my query. I think of adding where clause to the query but my queries are dynamic and I don't know whether there is any table alias in them or not! so I cant easily add where clause to my query. I can get query columns and tables from SqlDataReader but still I cant add where clause to the query because I dont know table alias names.
    Is there any way to do this? Is there any helper class?

    Sunday, October 18, 2009 12:30 PM