Results 1 to 4 of 4

Thread: [RESOLVED] Creating tables with 'CASE' statement?

  1. #1

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Resolved [RESOLVED] Creating tables with 'CASE' statement?

    Is it possible to use the CASE statement in a CREATE TABLE statement. I just thought that I could make the database more accurate this way. Say if i refer to products sold in a supermarket, some are measured by quantity and some are measured by weight. So if possible to have this statement:

    Code:
     
    CREATE TABLE tblProduct
    (
    	ProdCode	CHAR(8)		PRIMARY KEY,
    	ProdType	VARCHAR(8),
    	Prod_Desc	VARCHAR(40),
    	Unit		VARCHAR(12),
    	CentreName	CHAR(12)	REFERENCES tblDistCentre(CentreName),
    	/*DCStockLvl	(type to be decided by case statement) */
    );
    If the prodtype is FRESH (goods measured by weight) then I the DCStockLvl type will be FLOAT. However if the ProdType is 'PACKAGED' (goods measured by unit) then the type will be just a SMALLINT.
    The thought of using a CASE statement just occured to me, atm Ive just set-it up so that the type will just be a FLOAT.

    Thanks in advance,

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Creating tables with 'CASE' statement?

    A Field can only have one datatype.

  3. #3

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Re: Creating tables with 'CASE' statement?

    I initially thought that but somehow i just wanted to be creative. lol.
    Thanks

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] Creating tables with 'CASE' statement?

    Keep in mind that FLOAT datatypes yield inaccurate results in math calculations.

    It's always best to use a DECIMAL() or MONEY datatype.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width