• 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