Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
landau66
Yak Posting Veteran
61 Posts |
Posted - 2014-01-20 : 14:52:27
|
Hi everyone,I have several tables which are all identical in columns and datatypes. i want to create a function which does some calculations on this tables.Since I just want to create one function I Need to specify the table on which the function should work on. That means i want to pass the table Name as a Parameter to the function.Is that possible? Or how would you solve this problem.Thank you very much in advance and greetings from Austrialandau |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-01-20 : 14:57:00
|
You'd have to use a stored procedure as you can't use dynamic SQL in a function.But I would solve this problem by normalizing the database. You should not have tables like this.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
 |
|
landau66
Yak Posting Veteran
61 Posts |
Posted - 2014-01-20 : 15:04:52
|
hi tkizer!i have the Price data from several stocks. Ofcourse the structure of this tables is the same. Because of the facility of inspection i like to Keep the data of a stock in its own table.Or waht do you mean exactly?thank you very muchlandau |
 |
|
landau66
Yak Posting Veteran
61 Posts |
Posted - 2014-01-20 : 15:07:14
|
By the way:How would I enter the Name of the table into the stored procedure?thanks a lotlandau |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-01-20 : 15:11:39
|
quote: Originally posted by landau66 hi tkizer!i have the Price data from several stocks. Ofcourse the structure of this tables is the same. Because of the facility of inspection i like to Keep the data of a stock in its own table.Or waht do you mean exactly?
I would put the data into one table. Add another column if you need it to differentiate them, then use that column to get only the data you need.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-01-20 : 19:16:03
|
As Tara mentioned, part of the process of creating a proper schema is called Normalization. If you try to follow the rules of normalization you won't have to worry about trying to implements the hacks you are trying to do now.Here is a link that has a little information about the subject:http://en.wikipedia.org/wiki/Database_normalization |
 |
|
|
|
|