RadhaKrishnaKiJaya
asked on
Variables in SQL
Hello Experts,
Can I use variable file name in sql statement? For example Select *From @Variable_File_Name? Thank you very much in advance.
Thank you!
Can I use variable file name in sql statement? For example Select *From @Variable_File_Name? Thank you very much in advance.
Thank you!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Jeff Darling, Thank you for your help.
I have some tables like XX_2013, XX_2014, XX_2015 etc. I want to select the table based on the @YEAR parameter passed. It is not a new table I need to create, but need to select an existing one.
Thank you again!
I have some tables like XX_2013, XX_2014, XX_2015 etc. I want to select the table based on the @YEAR parameter passed. It is not a new table I need to create, but need to select an existing one.
Thank you again!
You really can't do that in SQL Server. SS doesn't allow variable object names.
To be honest, I believe your issue stems from bad design, especially if those tables are identical with data from different years. They should really be one table with a year column. Then querying it would be trivial.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OriNetworks,
Thank you for your help. Please read my comments above and let me know if you think it would create any issue in future.
Thank you again!
Thank you for your help. Please read my comments above and let me know if you think it would create any issue in future.
Thank you again!
ASKER
Already described.
Open in new window