need help in creating a procedure which uses cursor and variables

  • have situation where i need to create a procedure that uses another table data and fetches each table row and passes them as variables into the following user defined function (dbo.Split)

    The values id,SID,DOB are getting from another table columns values

    Soure table has

    ID ColNAME

    1 SID,DOB

    2 SID,DOB

    3 NAME,CITY,ZIP

    4 NAME,CITY,ZIP

    i need to use variables to fetch each row and pass them into the below function

    in the below mentioned function SID and DOB whould be passed as a variables from the source table

    select id, SID, DOB

    into table1

    from

    (

    select t.id,

    c.colname,

    c.colvalue

    from yt t

    cross apply dbo.split(t.name, t.text, ',') c

    where c.colname in ('SID', 'DOB')

    ) src

    pivot

    (

    max(colvalue)

    for colname in (SID, DOB)

    ) piv;

    select *

    from table1

    Can some one please help me

  • I wish I could help you, but I don't understand what you're trying to do.

    Please take a look at the article linked in my signature to obtain better help.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (4/18/2013)


    I wish I could help you, but I don't understand what you're trying to do.

    Please take a look at the article linked in my signature to obtain better help.

    It makes sense if you see this thread too, Luis.

    I don't see much point in following this potential solution until others have been considered first.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

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

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