Sunday, 15 January 2012

sql server 2005 - SQL: Best practice to store various fields in one table -


I want to create a table for the item There are several types of items, all the stock many fields near each type of item I want to store the unusual field in a different table. I thought something like this:

  ---- Item + Item_ID + Item snat_id + item side ... ... - --- Item_type + item snat_id + item_name ... ---- item_field + item_field_id + item_Type_Id + Field_Name ... ----file If you have the ability to add fields and values ​​without changing tables it is the value that you can see all the information for an item. For that I have to move area names and values.  

Any better suggestions? Or maybe a simple (not stored procedure) way to get into the tables to get a flat information? I tried to use PIIT (I am using SQL 2005) but no luck.

Thank you.

I have written a stored proc to make PIVOT more useful. Here's the source:

And some examples of using it:

For your data, the query should be just one Raw statistics to join in the tables listed above:

  set @ myQuery = 'select item, item_name, field_name, by value ...';  

Then your call will be on pivot_query:

  exec pivot_query @ myQuery, 'Item_Id, Item_Name', 'Field_Name', 'max (value)' < Like / code> 


No comments:

Post a Comment