Storing statistics of multple data types in SQL Server 2008

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-06T18:57:15Z Indexed on 2010/03/08 0:01 UTC
Read the original article Hit count: 472

I am creating a statistics module in SQL Server 2008 that allows users to save data in any number of formats (date, int, decimal, percent, etc...). Currently I am using a single table to store these values as type varchar, with an extra field to denote the datatype that it should be.

When I display the value, I use that datatype field to format it. I use sprocs to calculate the data for reporting; and the datatype field to convert to the appropriate datatype for the appropriate calculations.

This approach works, but I don't like storing all kinds of data in a varchar field. The only alternative that I can see is to have separate tables for each datatype I want to store, and save the record information to the appropriate table based on datatype. To retreive, I run a case statement to join the appropriate table and get the data. This seems to solve. This however, seems like a lot of work for ... what gain?

Wondering if I'm missing something here. Is there a better way to do this?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about sql-server-2008

Related posts about datatypes