Assign the variable based on the input

  • hi,

    I am having a requirement like this

    say if two table name is the input

    i will take 2 tables and need to create a view

    there may be common columns in the table ,so i need to assign the table name as "Table_1 as a"

    "Table_2 as b"

    i want to assign the alias name to the table.

    there may be 5 tables or even 10 tables so accordingly i need to assign the variable

    Thanks!

  • yuvipoy (1/29/2013)


    hi,

    I am having a requirement like this

    say if two table name is the input

    i will take 2 tables and need to create a view

    there may be common columns in the table ,so i need to assign the table name as "Table_1 as a"

    "Table_2 as b"

    i want to assign the alias name to the table.

    there may be 5 tables or even 10 tables so accordingly i need to assign the variable

    Thanks!

    It sounds like you are trying to create a new VIEW on-the-fly using table names that are passed in by an application. Can you clarify the requirement, maybe show an example?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • The dynamic naming is quite simple for something like this. The challenge is in how to join the tables. It can be done if you have foreign keys setup but let's face it that is not always the case. This is not generally a good idea due to the complexities you are going to face here. This has the sound of a user defined search type of thing?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

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

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