Script Field formats.

  • Hi I am starting to build a view in SQL Server 2000. The various fields need to be formatted as below :-

    Could someone possibly let me know how I go about doing this.

    Field NameFormat
    dflt_cyl_ctfNUMBER(18,4)
    cyl_ctf_actvINTEGER
    auto_cnt_drvr_dscrVARCHAR2(50)
    max_web_wdthdecimal(7,3)

    Any help would be gratefully received.

     

    Thanks!


    Kindest Regards,

    Nick

  • Hello Nick,

    Do you want the equivalent data types to SQL 2000? If so, you can check in BOL this topic

    data types-SQL Server, overview

    Field NameFormat
    dflt_cyl_ctfNUMERIC(18,4)
    cyl_ctf_actvINT
    auto_cnt_drvr_dscrVARCHAR(50)
    max_web_wdthdecimal(7,3)

    Hope this helps.

    Thanks

     


    Lucky

  • Don't think that's quite what Nick meant...

    Nick... You can do this by creating your view like this....

     CREATE VIEW dbo.someviewname AS

     SELECT CAST(dflt_cyl_ctf AS DECIMAL(18,4)) AS dflt_cyl_ctf,

            CAST(cyl_ctf_actv AS INT) AS cyl_ctf_actv,

            CAST(auto_cnt_drvr_dscr AS VARCHAR(50)) AS auto_cnt_drvr_dscr,

            CAST(max_web_wdth AS DECIMAL(7,3)) AS max_web_wdth

       FROM dbo.yourtable

    HOWEVER!!!! Views without the use of CAST return columns that have the same data-type as the columns in the SELECT of the view... why do you thing you need to change them?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Gentlemen,

    Excellent replies. Thankyou for your assistance.


    Kindest Regards,

    Nick

  • Thanks Nick... I'm still curious though... why do you need to change the datatype of a column in a view?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply