Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

T-SQL Cursors Expand / Collapse
Author
Message
Posted Tuesday, October 16, 2012 9:03 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 16, 2012 9:04 PM
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
Post #1373605
Posted Tuesday, October 16, 2012 10:14 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, August 6, 2014 9:41 PM
Points: 203, Visits: 57
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.
Post #1373615
Posted Thursday, November 1, 2012 6:55 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 4:53 AM
Points: 3,422, Visits: 5,368
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!
Post #1380098
Posted Tuesday, November 13, 2012 2:13 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 2:51 AM
Points: 3,076, Visits: 3,194
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 Seavus
www.seavus.com
Post #1384298
Posted Thursday, November 15, 2012 9:27 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, November 17, 2014 2:27 AM
Points: 418, Visits: 652
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)

Post #1385242
Posted Wednesday, March 6, 2013 3:28 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 6:30 AM
Points: 973, Visits: 3,032
This sounds like an issue for the presentation layer and not the data layer.




The SQL Guy @ blogspot

@SeanPearceSQL

About Me
Post #1427266
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse