Professional Web Applications Themes

How to declare TinyInt constant numbers? - Microsoft SQL / MS SQL Server

Hello all, Here ---------------------------------- Select 1, column_name From a_table ---------------------------------- 1 is a constant of type Int by default. But I want it to be of type TinyInt, another way to do this without "cast (1 as tinyint)"?...

  1. #1

    Default How to declare TinyInt constant numbers?

    Hello all,

    Here
    ----------------------------------
    Select 1, column_name From a_table
    ----------------------------------
    1 is a constant of type Int by default.

    But I want it to be of type TinyInt, another way to
    do this without "cast (1 as tinyint)"?


    w. jORDAN Guest

  2. #2

    Default Re: How to declare TinyInt constant numbers?

    "w. jORDAN" <wmjordan163.com> wrote in message
    news:e2wV#xqPDHA.3768tk2msftngp13.phx.gbl...
    > Hello all,
    >
    > Here
    > ----------------------------------
    > Select 1, column_name From a_table
    > ----------------------------------
    > 1 is a constant of type Int by default.
    >
    > But I want it to be of type TinyInt, another way to
    > do this without "cast (1 as tinyint)"?
    No. You're going to have to cast it either within this statement,

    Are you afraid of potential performance implications of converting this to a
    tinyint? Is your receiving application really going to save that much
    allocation over using the default? Have you tried both ways to determine
    what the different in performance will be?

    If you're going to return a constant for every single row in the result,
    what's the point of putting it in the query at all?


    Aaron Bertrand [MVP] Guest

  3. #3

    Default Re: How to declare TinyInt constant numbers?

    Yes, I am afraid of potential performance implications.

    That's a portion of my query.
    I am creating a view which uses union to merge two selected
    result sets.
    The first select statement selects a tinyint column and another
    column, the second is the one select 1, col_name ...
    I want the view works like the original table that the first select
    statement selects, so i would like to try another way.

    Just like the following is what i want actually:
    -----------------------------------------------------
    Create Table Products
    (
    ProductID int identity primary key,
    TypeCode tinyint,
    Product nvarchar(255) NOT NULL
    )
    Create Table SpecialProducts
    (
    ProductID int identity primary key,
    Product nvarchar(255) NOT NULL
    )

    Create View (TypeID, Product) as
    Select TypeCode, Product from Products
    Union All
    Select 128, Product from SpecialProducts
    -----------------------------------------------------

    I examined the SQL execution plan, nothing differs between
    the casted and the non-casted statement. I just wonder
    whether this matters.

    "Aaron Bertrand [MVP]" <aaronTRASHaspfaq.com> wrote in msg
    news:OENK1RsPDHA.2160TK2MSFTNGP11.phx.gbl...
    > "w. jORDAN" <wmjordan163.com> wrote in message
    > news:e2wV#xqPDHA.3768tk2msftngp13.phx.gbl...
    > > Hello all,
    > >
    > > Here
    > > ----------------------------------
    > > Select 1, column_name From a_table
    > > ----------------------------------
    > > 1 is a constant of type Int by default.
    > >
    > > But I want it to be of type TinyInt, another way to
    > > do this without "cast (1 as tinyint)"?
    >
    > No. You're going to have to cast it either within this statement,
    >
    > Are you afraid of potential performance implications of converting this to
    a
    > tinyint? Is your receiving application really going to save that much
    > allocation over using the default? Have you tried both ways to determine
    > what the different in performance will be?
    >
    > If you're going to return a constant for every single row in the result,
    > what's the point of putting it in the query at all?
    >
    >

    w. jORDAN Guest

  4. #4

    Default Re: How to declare TinyInt constant numbers?

    OJ:

    It does helps, but i am using the thing in Create View.
    So "declare" does not works. :)
    Thanks,
    Jordan

    "oj" <nospam_ojngohome.com> wrote
    news:eeSx43rPDHA.2160TK2MSFTNGP11.phx.gbl...
    > it has to be casted somehow. another way would be...
    >
    > declare tiny tinyint
    > set tiny=1
    > select tiny,column_name from tb
    >
    > --
    > -oj
    > RAC v2.2 & QALite!
    > [url]http://www.rac4sql.net[/url]
    >
    >
    >
    > "w. jORDAN" <wmjordan163.com> wrote in message
    > news:e2wV%23xqPDHA.3768tk2msftngp13.phx.gbl...
    > > Hello all,
    > >
    > > Here
    > > ----------------------------------
    > > Select 1, column_name From a_table
    > > ----------------------------------
    > > 1 is a constant of type Int by default.
    > >
    > > But I want it to be of type TinyInt, another way to
    > > do this without "cast (1 as tinyint)"?
    > >
    > >
    >
    >

    w. jORDAN Guest

Similar Threads

  1. DECLARE SYNTAX
    By harpalshergill@gmail.com in forum MySQL
    Replies: 7
    Last Post: June 28th, 06:54 PM
  2. Can we declare external Application API ?
    By psoum in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: March 3rd, 05:54 PM
  3. Call/Declare Functions
    By Myrddraal webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 4
    Last Post: January 30th, 08:55 PM
  4. declare one variable
    By [ZaToPeK] in forum PHP Development
    Replies: 3
    Last Post: December 5th, 01:27 AM
  5. Error: Must Declare Variable
    By Boris Zakharin in forum ASP.NET General
    Replies: 2
    Last Post: July 22nd, 01:04 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139