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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-06-20 : 09:43:53
|
| Hariharan writes "I would like to create a function that return the value from a table. The name of the table will have to be picked up dynamically from another table. The table structure and the sequence of steps are listed below. Can you kindly help me in creating a function.Table [Material] {M_Code,M_Name,M_TableName}Table [Ledger1] {L_Date,L_ClQty,L_ClRate,L_ClValue}Each Record in the [Material] table will have a corresponding Ledger Table and the name of the Ledger Table is mentioned in the [Material] table.The function should be like ClValue(Material_Code,Date)The sequence of steps.1. Select @TableName=M_TableName from Material where M_Code=@Material_Code.2. Select @ClValue = L_ClValue from @TableName where L_Date=@Date.3. Return @ClValue" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-20 : 09:50:23
|
| One of the bad table designsYou need to make use of Dynamic SQLRefer thesehttp://www.sommarskog.se/dynamic_sql.htmlhttp://www.nigelrivett.net/SQLTsql/sp_executesql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|