Connecting Tech Pros Worldwide Help | Site Map

Q: Null values and NZ() in crosstab query

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 04:23 PM
John
Guest
 
Posts: n/a
Default Q: Null values and NZ() in crosstab query

I've read several prior posts in this group about using nz() to
convert null values to zero; however, I'm not sure how/where to
implement this function in my crosstab query.

The crosstab query (qryPromoFilm_NetCM_Crosstab) uses another query
(qryPromo_NetCM) as its source. The crosstab is used to show revenue
spread out through the twelve months. I need the months with null
values to have a "0" value.

This is the SQL for the crosstab query (qryPromoFilm_NetCM_Crosstab):
TRANSFORM Avg(qryPromo_NetCM.curNetCM) AS AvgOfcurNetCM
SELECT qryPromo_NetCM.strPromoTitle, qryPromo_NetCM.strTitle
FROM qryPromo_NetCM
GROUP BY qryPromo_NetCM.strPromoTitle, qryPromo_NetCM.strTitle
PIVOT qryPromo_NetCM.lngFiscalMonthID In (1,2,3,4,5,6,7,8,9,10,11,12);

This is the SQL for the crosstab query's source (qryPromo_NetCM):
SELECT tblPromos.strPromoTitle, tblFilms.strTitle,
tblPromo_NetCM.lngFiscalYear, tblFiscalMonths.strFiscalMonth,
tblPromo_NetCM.curNetCM, tblPromo_NetCM.lngFiscalMonthID,
tblPromo_Films.lngPromoFilmID
FROM tblPromos INNER JOIN ((tblFilms INNER JOIN tblPromo_Films ON
tblFilms.lngFilmID = tblPromo_Films.lngFilmID) INNER JOIN
(tblFiscalMonths INNER JOIN tblPromo_NetCM ON
tblFiscalMonths.lngFiscalMonthID = tblPromo_NetCM.lngFiscalMonthID) ON
tblPromo_Films.lngPromoFilmID = tblPromo_NetCM.lngPromoFilmID) ON
tblPromos.lngPromoID = tblPromo_Films.lngPromoID
ORDER BY tblPromos.strPromoTitle, tblFilms.strTitle,
tblPromo_NetCM.lngFiscalYear, tblPromo_NetCM.lngFiscalMonthID;


Any suggestions on where/how to implement the nz() function?

TIA,
John

  #2  
Old November 12th, 2005, 04:23 PM
DFS
Guest
 
Posts: n/a
Default Re: Null values and NZ() in crosstab query


"John" <soundneedle@hotmail.com> wrote in message
news:90fab935.0312041735.14156405@posting.google.c om...[color=blue]
> I've read several prior posts in this group about using nz() to
> convert null values to zero; however, I'm not sure how/where to
> implement this function in my crosstab query.[/color]


Most likely in the TRANSFORM line:

TRANSFORM Avg(nz(qryPromo_NetCM.curNetCM)) AS AvgOfcurNetCM

I haven't tried nz() in a crosstab, but it may work. If not, I believe this
will:

TRANSFORM iif(isnull(qryPromo_NetCM.curNetCM),0,
avg(qryPromo_NetCM.curNetCM)) AS AvgOfcurNetCM



[color=blue]
> The crosstab query (qryPromoFilm_NetCM_Crosstab) uses another query
> (qryPromo_NetCM) as its source. The crosstab is used to show revenue
> spread out through the twelve months. I need the months with null
> values to have a "0" value.
>
> This is the SQL for the crosstab query (qryPromoFilm_NetCM_Crosstab):
> TRANSFORM Avg(qryPromo_NetCM.curNetCM) AS AvgOfcurNetCM
> SELECT qryPromo_NetCM.strPromoTitle, qryPromo_NetCM.strTitle
> FROM qryPromo_NetCM
> GROUP BY qryPromo_NetCM.strPromoTitle, qryPromo_NetCM.strTitle
> PIVOT qryPromo_NetCM.lngFiscalMonthID In (1,2,3,4,5,6,7,8,9,10,11,12);
>
> This is the SQL for the crosstab query's source (qryPromo_NetCM):
> SELECT tblPromos.strPromoTitle, tblFilms.strTitle,
> tblPromo_NetCM.lngFiscalYear, tblFiscalMonths.strFiscalMonth,
> tblPromo_NetCM.curNetCM, tblPromo_NetCM.lngFiscalMonthID,
> tblPromo_Films.lngPromoFilmID
> FROM tblPromos INNER JOIN ((tblFilms INNER JOIN tblPromo_Films ON
> tblFilms.lngFilmID = tblPromo_Films.lngFilmID) INNER JOIN
> (tblFiscalMonths INNER JOIN tblPromo_NetCM ON
> tblFiscalMonths.lngFiscalMonthID = tblPromo_NetCM.lngFiscalMonthID) ON
> tblPromo_Films.lngPromoFilmID = tblPromo_NetCM.lngPromoFilmID) ON
> tblPromos.lngPromoID = tblPromo_Films.lngPromoID
> ORDER BY tblPromos.strPromoTitle, tblFilms.strTitle,
> tblPromo_NetCM.lngFiscalYear, tblPromo_NetCM.lngFiscalMonthID;
>
>
> Any suggestions on where/how to implement the nz() function?
>
> TIA,
> John[/color]


  #3  
Old November 12th, 2005, 04:23 PM
Rick Brandt
Guest
 
Posts: n/a
Default Re: Null values and NZ() in crosstab query

"John" <soundneedle@hotmail.com> wrote in message
news:90fab935.0312041735.14156405@posting.google.c om...[color=blue]
> I've read several prior posts in this group about using nz() to
> convert null values to zero; however, I'm not sure how/where to
> implement this function in my crosstab query.[/color]

I'm not real sure what it would look like in the SQL, but essentially if
you look at the Crosstab in the design grid the column being aggregated
will typically have "Sum" or "Count" in the Total Row and the name of the
field being aggregated in the Field row. You change the Total row to
"Expression" and then change the Field row to "Nz(Sum(FieldName),0)" or
Nz(Count(FieldName),0). Then you get zeros in the output instead of Nulls.
I usually throw a "+0" onto end of the expression to force a numeric
output. Otherwise the Nz() will change the output to a string.


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


  #4  
Old November 12th, 2005, 04:25 PM
John
Guest
 
Posts: n/a
Default Re: Null values and NZ() in crosstab query

Rick, your suggestion worked just fine...thanks a lot for your help!

-John

"Rick Brandt" <rickbrandt2@hotmail.com> wrote in message news:<bqq1q9$25fa6q$1@ID-98015.news.uni-berlin.de>...[color=blue]
> "John" <soundneedle@hotmail.com> wrote in message
> news:90fab935.0312041735.14156405@posting.google.c om...[color=green]
> > I've read several prior posts in this group about using nz() to
> > convert null values to zero; however, I'm not sure how/where to
> > implement this function in my crosstab query.[/color]
>
> I'm not real sure what it would look like in the SQL, but essentially if
> you look at the Crosstab in the design grid the column being aggregated
> will typically have "Sum" or "Count" in the Total Row and the name of the
> field being aggregated in the Field row. You change the Total row to
> "Expression" and then change the Field row to "Nz(Sum(FieldName),0)" or
> Nz(Count(FieldName),0). Then you get zeros in the output instead of Nulls.
> I usually throw a "+0" onto end of the expression to force a numeric
> output. Otherwise the Nz() will change the output to a string.[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.