please give me a solution for this request

  • sir i have a table values like this

    10 null null

    null name null

    null null hyd..

    then i want to get in a single row sir.....

  • Per the rules of this site, -

    - please post the full DDL for your table;

    - include some test data; and

    -show the expected outcome.

    It is darn difficult to help you if any of these is missing.

    It is 10:35 PM of my local time but I will hang around for at least half an hour to help you if you provide the info I need.

  • //this is my table

    create table std_table

    (

    id int,

    name nvarchar,

    address nvarchar,

    )

    //this is my table data

    10 null null

    null anilkuar null

    null null hyderabad

    //i want the data like this

    10 anilkumar hyderbad

  • anil.janu143 (4/22/2012)


    //this is my table

    create table std_table

    (

    id int,

    name nvarchar,

    address nvarchar,

    )

    //this is my table data

    10 null null

    null anilkuar null

    null null hyderabad

    //i want the data like this

    10 anilkumar hyderbad

    Your table has exactly three rows of data, and will never ever have any more than that?

  • anil.janu143 (4/22/2012)


    //this is my table

    create table std_table

    (

    id int,

    name nvarchar,

    address nvarchar,

    )

    //this is my table data

    10 null null

    null anilkuar null

    null null hyderabad

    //i want the data like this

    10 anilkumar hyderbad

    Given nothing else for test data, the current solution would be...

    SELECT MAX(ID), MAX(Name), MAX(Address)

    FROM dbo.yourtable

    If you'd like a more detailed answer, please see the first link in my signature line below. Thanks.

    --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)

  • anil.janu143 (4/22/2012)


    //this is my table

    create table std_table

    (

    id int,

    name nvarchar,

    address nvarchar,

    )

    //this is my table data

    10 null null

    null anilkuar null

    null null hyderabad

    //i want the data like this

    10 anilkumar hyderbad

    If the rows are always multiples of three, this will work:

    use Temp

    go

    create table $temp (

    tempId int identity(1, 1)

    ,t.id int NULL

    ,t1.[name] nvarchar (50) NULL

    ,t2.[address] nvarchar (50) NULL

    );

    insert into @temp (id, name, address)

    select * from std_table

    ;

    select id

    ,name

    ,address

    from @temp AS t

    JOIN @temp AS t1

    ON t1.tempId = t.tempId + 1

    JOIN @temp AS t2

    ON t2.tempId = t.tempId + 2

    where id IS NOT NULL

    ;

    You may have to tweak it a bit, but the idea is to insert the data into a new table with IDENTITY and do JOINs on that.

  • Please post some more sample data.

    If you only give this much sample data then the solutions provided might not work always.

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

  • Solution is, tell whomever put the data in the table to do it again, but do it right this time. Don't split the data across multiple rows like that.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (4/23/2012)


    Solution is, tell whomever put the data in the table to do it again, but do it right this time. Don't split the data across multiple rows like that.

    +1 however i saw this same question as homework for one of my sql classes.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • capn.hector (4/23/2012)


    GSquared (4/23/2012)


    Solution is, tell whomever put the data in the table to do it again, but do it right this time. Don't split the data across multiple rows like that.

    +1 however i saw this same question as homework for one of my sql classes.

    There are SQL classes... Therein lies the problem.

    Jared
    CE - Microsoft

  • So Jeff and I have done someone's homework...

  • capn.hector (4/23/2012)


    +1 however i saw this same question as homework for one of my sql classes.

    Interesting! Where did you take such a class? I ask because it's not exactly a BOL or CERT question and it's nice to see such classes teaching a practical thing (in this case, the pre-cursor to how CROSS TABS work).

    --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)

  • Jeff Moden (4/23/2012)


    capn.hector (4/23/2012)


    +1 however i saw this same question as homework for one of my sql classes.

    Interesting! Where did you take such a class? I ask because it's not exactly a BOL or CERT question and it's nice to see such classes teaching a practical thing (in this case, the pre-cursor to how CROSS TABS work).

    It's a good thing as long as they teach that this data "should" never exist 🙂 We don't want people to learn that "there are script fixes for bad design, so who cares about the design." I only say this because I have worked with developers who think it is my job to return the data properly, but they can store it however they want.

    Jared
    CE - Microsoft

  • SQLKnowItAll (4/23/2012)


    Jeff Moden (4/23/2012)


    capn.hector (4/23/2012)


    +1 however i saw this same question as homework for one of my sql classes.

    Interesting! Where did you take such a class? I ask because it's not exactly a BOL or CERT question and it's nice to see such classes teaching a practical thing (in this case, the pre-cursor to how CROSS TABS work).

    It's a good thing as long as they teach that this data "should" never exist 🙂 We don't want people to learn that "there are script fixes for bad design, so who cares about the design." I only say this because I have worked with developers who think it is my job to return the data properly, but they can store it however they want.

    it was a question during our transform data to normalize a bad design segment of a database design course. it went about like this: there is this table with bad data like so (ID,col1,col2,col2) Values (1,stuff,null,null),(1,null,stuff,null),(1,null,null,stuff),(2,Stuff,null,null)... how can you fix the data to normalize the table and get rid of the bad design?


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • SQLKnowItAll (4/23/2012)


    Jeff Moden (4/23/2012)


    capn.hector (4/23/2012)


    +1 however i saw this same question as homework for one of my sql classes.

    Interesting! Where did you take such a class? I ask because it's not exactly a BOL or CERT question and it's nice to see such classes teaching a practical thing (in this case, the pre-cursor to how CROSS TABS work).

    It's a good thing as long as they teach that this data "should" never exist 🙂 We don't want people to learn that "there are script fixes for bad design, so who cares about the design." I only say this because I have worked with developers who think it is my job to return the data properly, but they can store it however they want.

    Yep... I agree with doing it right upfront but it's really nice to see someone actually trying to teach how to fix things that are bad. Too often I see courses based only on "perfect conditions" and the real world isn't quite so kind.

    --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)

Viewing 15 posts - 1 through 15 (of 16 total)

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