Professional Web Applications Themes

Many values from a single field returned into one single string - Microsoft SQL / MS SQL Server

The info. you have specified is not sufficient. is this a single column from which you are retrieving the values. If yes what is the replacement holder for "," . i mean are the spaces in the string needs to be replaced by commas ? If yes, then you can have something like this. select replace(column1, ' ', ',') from table -- -Vishal "Nicolas Verhaeghe" <com_nospam> wrote in message news:XvU0b.20$randori.com...  one  string ...

  1. #1

    Default Re: Many values from a single field returned into one single string

    The info. you have specified is not sufficient.
    is this a single column from which you are retrieving the values. If yes
    what is the replacement holder for "," . i mean are the spaces in the string
    needs to be replaced by commas ?
    If yes, then you can have something like this.

    select replace(column1, ' ', ',') from table


    --
    -Vishal
    "Nicolas Verhaeghe" <com_nospam> wrote in message
    news:XvU0b.20$randori.com... 
    one 
    string 



    Vishal Guest

  2. #2

    Default Many values from a single field returned into one single string

    --Maybe something like the following:

    declare RtnString varchar(8000)
    select RtnString = '"'
    select RtnString = RtnString + name +','
    from master.dbo.systypes

    select RtnString = left(RtnString, len
    (RtnString) - 1),
    RtnString = RtnString + '"'

    print RtnString
     
    into a CSV string 
    that one field one 
    is not empty. 
    values in a string 
    Art Guest

  3. #3

    Default Re: Many values from a single field returned into one single string

    I do not think you took the time to read "the info" I specified.

    The comma is there to separate values, hence it being called a "CSV".
     
    string 


    Nicolas Guest

  4. #4

    Default Many values from a single field returned into one single string

    I will reformulate my question:

    Say I have a table called "myTable" with a field called "myValue":

    The Statement:

    SELECT MyValue
    FROM MyTable
    ORDER BY MyValue

    Gives:

    MyValue
    -------
    2
    5
    7
    8

    What I am trying to know is if there is a way to get this:

    smyValueString = "2,5,7,8"

    .... without using a Cursor but rather a SINGLE SELECT statement.

    If not, then I will use a cursor.

    Thanks in advance for your help!


    Nicolas Guest

  5. #5

    Default Re: Many values from a single field returned into one single string

    declare s varchar(8000)

    select s=isnull(s+',','') +convert(varchar,s1.id) from
    student s1
    select s 
    wrote in message [/ref]
    called "myValue": [/ref]
    this: [/ref]
    statement. 
    >
    >
    >.
    >[/ref]
    nav Guest

  6. #6

    Default Re: Many values from a single field returned into one single string

    Thanks.

    This returns ,2,3,5,6,8

    I guess I can remove the first character by using a substring?

    Otherwise what is the trailing "x" after the closing parenthesis?

    Thanks for your help!

    "oj" <com> wrote in message
    news:%phx.gbl... 
    >
    >[/ref]


    Nicolas Guest

Similar Threads

  1. how do i take a multi page single file & makeit single page single files?
    By Paul_A._Collins@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 6
    Last Post: December 4th, 04:05 PM
  2. Inserting multiple values into a single db field
    By ktmx in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: April 5th, 07:35 PM
  3. Multiple values into a single field
    By ktmx in forum Coldfusion Database Access
    Replies: 6
    Last Post: April 4th, 05:35 PM
  4. Replies: 3
    Last Post: August 15th, 10:52 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