May 15, 2012 at 3:14 am
I just wonder how I can solve a problem with a NULL-value being change into another value when I fetch the data from my statement into the variable (var_5)...
If the bold-text column (tb_2.column_2) is NULL then I would like to put the value "Undefined" into the bold-text variable (var_5).
BEGIN
DECLARE C2 CURSOR READ_ONLY
FOR
SELECT
count(*),
sum(tb_1.column_1),
sum(tb_1.column_2),
SUM(tb_1.column_3),
tb_2.column_2
FROM tb_1
LEFT OUTER JOIN tb_2 ON tb_1.column_4 = tb_2.column_4
WHERE tb_1.column_5 = criteria
GROUP BY tb_2.column_2
END
OPEN C2
FETCH NEXT FROM C2 INTO
@var_1, @var_2, @var_3, @var_4, @var_5
May 15, 2012 at 3:28 am
ISNULL(tb_2.column_2, 'Undefined')
May 15, 2012 at 3:42 am
Eugene Elutin (5/15/2012)
ISNULL(tb_2.column_2, 'Undefined')
You didn't mention the 'c' word...
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
May 15, 2012 at 3:45 am
Sometimes the answer is right in front of you... Tnx!
May 15, 2012 at 3:51 am
Phil Parkin (5/15/2012)
Eugene Elutin (5/15/2012)
ISNULL(tb_2.column_2, 'Undefined')You didn't mention the 'c' word...
Or, yeah!:cool:
To OP:
Are you sure you need a cursor for what you're doing?
May 15, 2012 at 3:57 am
Yes I do...
I am creating a job that will send emails every morning showing different data that has occured during the last day. Some of the data that is sent sometimes holds the value NULL so to spare you 100 rows of code I simply cut out a peice to show here...
May 15, 2012 at 4:05 am
jonas.kasper (5/15/2012)
Yes I do...I am creating a job that will send emails every morning showing different data that has occured during the last day. Some of the data that is sent sometimes holds the value NULL so to spare you 100 rows of code I simply cut out a peice to show here...
Looks like legitimate reason to me for using cursor.
Any objections, anyone?
😉
May 15, 2012 at 11:56 am
Eugene Elutin (5/15/2012)
jonas.kasper (5/15/2012)
Yes I do...I am creating a job that will send emails every morning showing different data that has occured during the last day. Some of the data that is sent sometimes holds the value NULL so to spare you 100 rows of code I simply cut out a peice to show here...
Looks like legitimate reason to me for using cursor.
Any objections, anyone?
😉
Actually, I do this all the time and I never needed a cursor to do it.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
May 15, 2012 at 7:01 pm
RBarryYoung (5/15/2012)
Eugene Elutin (5/15/2012)
jonas.kasper (5/15/2012)
Yes I do...I am creating a job that will send emails every morning showing different data that has occured during the last day. Some of the data that is sent sometimes holds the value NULL so to spare you 100 rows of code I simply cut out a peice to show here...
Looks like legitimate reason to me for using cursor.
Any objections, anyone?
😉
Actually, I do this all the time and I never needed a cursor to do it.
"There must be 50 ways to lose your cursors..." 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
May 15, 2012 at 9:02 pm
Jeff Moden (5/15/2012)
RBarryYoung (5/15/2012)
Eugene Elutin (5/15/2012)
jonas.kasper (5/15/2012)
Yes I do...I am creating a job that will send emails every morning showing different data that has occured during the last day. Some of the data that is sent sometimes holds the value NULL so to spare you 100 rows of code I simply cut out a peice to show here...
Looks like legitimate reason to me for using cursor.
Any objections, anyone?
😉
Actually, I do this all the time and I never needed a cursor to do it.
"There must be 50 ways to lose your cursors..." 😀
Yes, at least that many.
😎
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
May 16, 2012 at 5:19 am
OK. I could use a bunch of while-loops but hey, I think it's an easy and comfortable way to write my code. And it's neat for the eye...
By the way here's another problem I need help with...
http://www.sqlservercentral.com/Forums/Topic1300914-391-1.aspx
May 16, 2012 at 5:38 am
jonas.kasper (5/16/2012)
OK. I could use a bunch of while-loops but hey, I think it's an easy and comfortable way to write my code. And it's neat for the eye...By the way here's another problem I need help with...
http://www.sqlservercentral.com/Forums/Topic1300914-391-1.aspx
When we say "No Cursors", we also mean "And Definitely No While Loops". I never use either one. Not even for my mail jobs.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
May 16, 2012 at 6:59 am
RBarryYoung (5/15/2012)
Jeff Moden (5/15/2012)
RBarryYoung (5/15/2012)
Eugene Elutin (5/15/2012)
jonas.kasper (5/15/2012)
Yes I do...I am creating a job that will send emails every morning showing different data that has occured during the last day. Some of the data that is sent sometimes holds the value NULL so to spare you 100 rows of code I simply cut out a peice to show here...
Looks like legitimate reason to me for using cursor.
Any objections, anyone?
😉
Actually, I do this all the time and I never needed a cursor to do it.
"There must be 50 ways to lose your cursors..." 😀
Yes, at least that many.
😎
Just slip out the back-end Jack
Makin no query plans Sam ...
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply