There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot browser bsod computer cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware missing monitor network networking outlook outlook 2003 outlook 2007 outlook express password popups problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Problems with SQL Statement (Nulls)


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
coachdan32's Avatar
Computer Specs
Senior Member with 1,000 posts.
 
Join Date: Nov 2003
Location: Louisville, KY
23-Jun-2004, 08:45 AM #1
Question Problems with SQL Statement (Nulls)
There is a problem with my syntax in the following SQL statement:

SQLSP = SQLSP & " Sum(IIf([StdtProdAS]![W1AHT]="",0,[StdtProdAS]![W1AHT])+IIf([StdtProdAS]![W2AHT]="",0,[StdtProdAS]![W2AHT])+IIf([StdtProdAS]![W3AHT]="",0,[StdtProdAS]![W3AHT])+IIf([StdtProdAS]![W4AHT]="",0,[StdtProdAS]![W4AHT])) AS AHTSum, "

I am trying to test for a null value before performing the addition and if it contains null, use "0" as the number in the addition.
__________________
CoachDan
http://www.malehsbaseball.com

Gateway Pentium 4 3.0 GHz
200G Sata HD
800 FSB
512 DDR
DVD +-R/W
XP Home
coachdan32's Avatar
Computer Specs
Senior Member with 1,000 posts.
 
Join Date: Nov 2003
Location: Louisville, KY
23-Jun-2004, 09:42 AM #2
Have also tried:

SQLSP = SQLSP & " Sum(IIf(IsNull([StdtProdAS]![W1AHT],0,[StdtProdAS]![W1AHT])+IIf(IsNull([StdtProdAS]![W2AHT],0,[StdtProdAS]![W2AHT])+IIf(IsNull([StdtProdAS]![W3AHT],0,[StdtProdAS]![W3AHT])+IIf(IsNull([StdtProdAS]![W4AHT],0,[StdtProdAS]![W4AHT]))))) AS AHTSum, "
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
23-Jun-2004, 10:09 AM #3
What are you getting for a result and what do you want the null values to be 0? It looks like you need to seperate each value and then add it together instead of in one grouping. I am starting to think that they really aren't NULL values at all.
__________________
**Disclaimer** Anything below this line ^ is part of my signature for those that may be confused

Sadly, there are no integers on this scale, so your gangly adolescent attempt to be clever has proved futile....Dieter

I have the right "NOT" to be tolerant of others because they are different, weird, or tick me off.....Parody of Andy Rooney

There are no stupid questions, but there are a LOT of inquisitive idiots.
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
23-Jun-2004, 10:17 AM #4
Try this and see if it works. After you create your recordset create some string variables based on the values you are testing for NULL, something like this:

strW1AHT = Iif(InNulll([StdtProdAS]![W1AHT],0,[StdtProdAS]![W1AHT]))

and do the same for the other three fields you want to add up. Now just add up the variables. You can now use them in other areas of the page again as long as the recordset is open.

Add up the strings:

Sum strW1AHT + strW2AHT + strW3AHT + strW4AHT
__________________
**Disclaimer** Anything below this line ^ is part of my signature for those that may be confused

Sadly, there are no integers on this scale, so your gangly adolescent attempt to be clever has proved futile....Dieter

I have the right "NOT" to be tolerant of others because they are different, weird, or tick me off.....Parody of Andy Rooney

There are no stupid questions, but there are a LOT of inquisitive idiots.
coachdan32's Avatar
Computer Specs
Senior Member with 1,000 posts.
 
Join Date: Nov 2003
Location: Louisville, KY
23-Jun-2004, 10:33 AM #5
I am getting a Provider for ODBC Drivers error '80040e14' - Syntax error in query expression and then it is regurgitating the SQL code in question as posted above. I do want it to return 0 if there is no data present. I will give your suggestion a try also.
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
23-Jun-2004, 10:38 AM #6
BTW, you cannot use the IIF in ASP, you have to use the IF THEN and END IF
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:26 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.