Professional Web Applications Themes

how to add another column to a query result? - Microsoft SQL / MS SQL Server

hi guys, I have a query that will return 4 record with 1 column. I want to add another "title" column for the four record. The query is design so that it will only return 4 record. any help is really appreciated. thanks, Jun...

  1. #1

    Default how to add another column to a query result?

    hi guys,
    I have a query that will return 4 record with 1 column.
    I want to add another "title" column for the four record.
    The query is design so that it will only return 4 record.
    any help is really appreciated.
    thanks,

    Jun


    Junaili Lie Guest

  2. #2

    Default Re: how to add another column to a query result?

    Select <columns already selected>, 'title' as Title
    From <tablename>

    Junaili Lie wrote:
    > hi guys,
    > I have a query that will return 4 record with 1 column.
    > I want to add another "title" column for the four record.
    > The query is design so that it will only return 4 record.
    > any help is really appreciated.
    > thanks,
    >
    > Jun

    Bob Barrows Guest

  3. #3

    Default Re: how to add another column to a query result?

    Thanks for the quick reply

    I think I might confuse you.

    What I meant was creating a 'title' column and populate each row with four
    different title.

    e.g.

    Title Value

    -----------

    "t1" 1

    "t2" 2

    "t3" 3

    "t4" 4

    initially, the query will return:

    Value

    -----

    1

    2

    3

    4

    Thanks again

    "Bob Barrows" <reb_01501> wrote in message
    news:OZDxn0KRDHA.560TK2MSFTNGP10.phx.gbl...
    > Select <columns already selected>, 'title' as Title
    > From <tablename>
    >
    > Junaili Lie wrote:
    > > hi guys,
    > > I have a query that will return 4 record with 1 column.
    > > I want to add another "title" column for the four record.
    > > The query is design so that it will only return 4 record.
    > > any help is really appreciated.
    > > thanks,
    > >
    > > Jun
    >
    >

    Junaili Lie Guest

  4. #4

    Default Re: how to add another column to a query result?

    SELECT title = 't'+CAST(value AS VARCHAR), value FROM table

    Don't see how this is valuable, can't the client application do that?




    "Junaili Lie" <junaili_liehotmail.com> wrote in message
    news:#rkcwBLRDHA.560TK2MSFTNGP10.phx.gbl...
    > Thanks for the quick reply
    >
    > I think I might confuse you.
    >
    > What I meant was creating a 'title' column and populate each row with four
    > different title.
    >
    > e.g.
    >
    > Title Value
    >
    > -----------
    >
    > "t1" 1
    >
    > "t2" 2
    >
    > "t3" 3
    >
    > "t4" 4
    >
    > initially, the query will return:
    >
    > Value
    >
    > -----
    >
    > 1
    >
    > 2
    >
    > 3
    >
    > 4
    >
    > Thanks again
    >
    > "Bob Barrows" <reb_01501> wrote in message
    > news:OZDxn0KRDHA.560TK2MSFTNGP10.phx.gbl...
    > > Select <columns already selected>, 'title' as Title
    > > From <tablename>
    > >
    > > Junaili Lie wrote:
    > > > hi guys,
    > > > I have a query that will return 4 record with 1 column.
    > > > I want to add another "title" column for the four record.
    > > > The query is design so that it will only return 4 record.
    > > > any help is really appreciated.
    > > > thanks,
    > > >
    > > > Jun
    > >
    > >
    >
    >

    Aaron Bertrand - MVP Guest

  5. #5

    Default Re: how to add another column to a query result?

    Hi

    Try (untested!)

    ALTER Table MyTable ADD Title CHAR(2)

    UPDATE MyTable SET Title = CASE Value WHEN 1 THEN 'T1'
    WHEN 2 THEN 'T2'
    WHEN 3 THEN 'T3'
    WHEN 4 THEN 'T4'
    END


    John


    "Junaili Lie" <junaili_liehotmail.com> wrote in message
    news:#rkcwBLRDHA.560TK2MSFTNGP10.phx.gbl...
    > Thanks for the quick reply
    >
    > I think I might confuse you.
    >
    > What I meant was creating a 'title' column and populate each row with four
    > different title.
    >
    > e.g.
    >
    > Title Value
    >
    > -----------
    >
    > "t1" 1
    >
    > "t2" 2
    >
    > "t3" 3
    >
    > "t4" 4
    >
    > initially, the query will return:
    >
    > Value
    >
    > -----
    >
    > 1
    >
    > 2
    >
    > 3
    >
    > 4
    >
    > Thanks again
    >
    > "Bob Barrows" <reb_01501> wrote in message
    > news:OZDxn0KRDHA.560TK2MSFTNGP10.phx.gbl...
    > > Select <columns already selected>, 'title' as Title
    > > From <tablename>
    > >
    > > Junaili Lie wrote:
    > > > hi guys,
    > > > I have a query that will return 4 record with 1 column.
    > > > I want to add another "title" column for the four record.
    > > > The query is design so that it will only return 4 record.
    > > > any help is really appreciated.
    > > > thanks,
    > > >
    > > > Jun
    > >
    > >
    >
    >

    John Bell Guest

Similar Threads

  1. How to pass query result from pop-up?
    By Mariusz Topczewski in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: December 21st, 04:09 PM
  2. Format query result.
    By Kasper K in forum MySQL
    Replies: 2
    Last Post: June 29th, 02:19 PM
  3. displaying query result of 0 as N/A
    By eggwater in forum Macromedia ColdFusion
    Replies: 3
    Last Post: May 10th, 11:34 AM
  4. How to deal with big query result?
    By Lin Ma in forum ASP
    Replies: 2
    Last Post: October 10th, 04:16 PM
  5. 2 horizontal column, but with odd number of result = empty cell!!
    By Jay in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: August 28th, 07:47 PM

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