Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Assign the variable based on the input Expand / Collapse
Author
Message
Posted Tuesday, January 29, 2013 11:34 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 12:41 AM
Points: 110, Visits: 513
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!
Post #1413461
Posted Thursday, January 31, 2013 5:59 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:44 PM
Points: 6,703, Visits: 11,734
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

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1414048
Posted Thursday, January 31, 2013 9:06 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 2:34 PM
Points: 8,592, Visits: 8,233
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1414192
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse