T-SQL Cursors

  • Okay I am kind of new to this and I am trying to create a table and if the user doesn't fill all the fields I need the empty field to not be shown just the fields that are filled. How can I do this using a cursor? Any pointers??

    thanks in advance

  • computergirl (10/16/2012)


    Okay I am kind of new to this and I am trying to create a table and if the user doesn't fill all the fields I need the empty field to not be shown just the fields that are filled. How can I do this using a cursor? Any pointers??

    thanks in advance

    Could you elaborate on this one. Some thing like a sample so, that we could answer or give ideas on your question. 🙂

  • computergirl (10/16/2012)


    Okay I am kind of new to this and I am trying to create a table and if the user doesn't fill all the fields I need the empty field to not be shown just the fields that are filled. How can I do this using a cursor? Any pointers??

    thanks in advance

    Agreed that elaboration is needed.

    First of all you refer to "fields" but SQL tables contain "columns." How many columns?

    Neither can columns be "empty" - they can be NULL (which is another way to say the value is unknown).

    Are you saying you want to write a query that only returns a column if that column does not contain a NULL value?

    Refer to the first line in my signature. If you are new it's not too late for you. Don't think about CURSORs as a first resort. SQL processes sets, so you should think of sets first and 99.9% of the time you can solve the problem without resorting to a CURSOR (that should always be a last resort).


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • computergirl (10/16/2012)


    Okay I am kind of new to this and I am trying to create a table and if the user doesn't fill all the fields I need the empty field to not be shown just the fields that are filled. How can I do this using a cursor? Any pointers??

    thanks in advance

    Hi,

    Because you're a newbie you'd better read this first: http://www.sqlservercentral.com/articles/Best+Practices/61537/

    May be you think of usage ISNULL, COALESCE, or something else ... in your loop, but with such explanation we could just imagine what you need.

    Regards

    IgorMi

    Igor Micev,My blog: www.igormicev.com

  • This doesn't read like an SQL issue, more a GUI issue.

    I may be wrong but it sounds like what she wants is that if the field is NULL then do not display the field on the form

    Changing the number of columns returned by a query would require Dynamic SQL which should be avoided whenever possible for a number of reasons

    (SQL injection attacks and query plan cacheing to name two)

  • This sounds like an issue for the presentation layer and not the data layer.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

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