Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


T-SQL Cursors


T-SQL Cursors

Author
Message
computergirl
computergirl
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 3
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
sriren6029
sriren6029
SSC Veteran
SSC Veteran (213 reputation)SSC Veteran (213 reputation)SSC Veteran (213 reputation)SSC Veteran (213 reputation)SSC Veteran (213 reputation)SSC Veteran (213 reputation)SSC Veteran (213 reputation)SSC Veteran (213 reputation)

Group: General Forum Members
Points: 213 Visits: 63
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. :-)
dwain.c
dwain.c
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4249 Visits: 6431
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!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Igor Micev
Igor Micev
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4164 Visits: 4843
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,SQL Server developer at Seavuswww.seavus.com
aaron.reese
aaron.reese
Mr or Mrs. 500
Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)

Group: General Forum Members
Points: 589 Visits: 898
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)
Sean Pearce
Sean Pearce
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1170 Visits: 3432
This sounds like an issue for the presentation layer and not the data layer.



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search