Please help with the code

  • Actually I have table called fuits which has column name fruits_type having records like

    record1:apple banana & mango

    record2:apple chickoo & peach

    It has fruit id as identity column. I should split data for first record like row1-apple

    row2-banana & mango and in similar ways for second record it sud like row1-apple

    row2-chickoo & peach

    Here delimiter is char(30)+char(10)

    I tried to write split function as follow:

    declare @string

    declare @delimiter

    select @string=fruits_type from fruits where fruit_id=1

    set @delimiter=char(30)+char(10)

    There are lot of records like this in that table. so final result sud be like

    frui_id fruit_tpye

    1 apple

    2 banana & mango

    3 apple

    4 chickoo & peach

    This record has to be fetched in temp table but duplicate records have to be eliminated. so final temp table sud be like

    1 apple

    2 banana & mango

    3 chicko & peach

    I think we can write function or within stored procedure,we can write cursor for row by row procesing.But I don't know to write cmplx qurey.Please it's urgent.Can anyone help me with the code.It's too urgent.

  • Please check out the first link in my signature, and then try posting your data in that suggested format. Then, based on the sample data you provide, show what the expected results should be. I bet you will have a lot more people willing to help you out then.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • I wish they had the Internets back when I had homework assignments!

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

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

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