Please Help

  • Hi,

    I have a small problem.

    In a table there are 4 fields

    fld1 fld2 fld3 user_id

    x y z 1

    a b c 1

    d e f 2

    g h i 3

    I need a single query which does both these 2 things

    1.get all the distinct user-d's

    2.and get the corresponding rows for each user-id.

    I hope i made sense.

    Thanks

    Hari

  • Hari,

    How can a result set possibly contain only distinct user_ids, yet contain multiple rows for each ID which has more than one row? Can you show some example output?

    --
    Adam Machanic
    whoisactive

  • Ok..sorry i might have explained wrong..here is what i want..

    I have a table like below

    fld1 fld2 fld3 fld4

    123 abc

    123 def

    123 def

    456 xyz

    456 xyz

    789 ijk

    789 ijk

    I need a query so that , it can put in different text files the results as below

    Textfile1

    123 abc fld3value fld4value

    textfile2

    123 def fld3value fld4value

    123 def ....

    Textfile3

    456 xyz fld3value fld4value

    456 xyz....

    Etc…

    Thank you for the help

  • Hari,

    I'm not sure how to do this exclusively in T-SQL...  However, in VB, it wouldn't be too hard.

    You could make an ado connection to the DB.  Then create an ado recordset based on a select statement, which right now looks like Select * from tablename.  Then,  you could loop until recordset.EOF.  Within the loop, you write the current record to a unique text file.

    I can remember the VB function, but there is a date function (similar to getdate) that will give you the year/month/....down to the second.  You could convert that to a string and concatenate it with a file name for uniqueness.

    Idealy, someone on the list can write a stored proc that will do the same thing.

    Good Luck

    Ryan

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

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