Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I use the following code to get data from an Access database:

 

       selectSQLOnHand = "Select tblSalesOrderDetails.ItemID, " & _
                               "tblSalesOrderDetails.QtyOrdered, " & _
                               "FROM tblSalesOrderDetails " & _
                               "WHERE tblSalesOrderDetails.LineStatus = 'Closed' " & _
                               "GROUP BY tblSalesOrderDetails.ItemID"

 

In certain cases the value of QtyOrdered = Null, this value is bound to a textbox and used in certain calculations. The Null value is causing a problem in the calculations and needs to be somehow converted to a zero. Any ideas......

Posted

selectSQLOnHand = "Select tblSalesOrderDetails.ItemID, " & _

"IIf(IsNull(tblSalesOrderDetails.QtyOrdered), 0, tblSalesOrderDetails.QtyOrdered), " & etc...

Posted

Still getting a Null

 

Thanks for your help but I'm still getting a Null value reurned. Not sure if the GROUP BY is causing the problem...

 

       selectSQLOnHand = "Select tblPurchaseOrderDetails.ItemID, " & _
                               "IIf(IsNull(sum(tblPurchaseOrderDetails.POQtyReceived)), 0, sum(tblPurchaseOrderDetails.POQtyReceived)) As OnHand  " & _
                               "FROM tblPurchaseOrderDetails " & _
                               "GROUP BY tblPurchaseOrderDetails.ItemID"

Posted

Really Strange Null Issue - Still not solved

 

On the above code if there is a value for the sum(tblPurchaseOrderDetails.POQtyReceived) it will return the True value correctly I tested this by putting

"IIf(IsNull(sum(tblPurchaseOrderDetails.POQtyReceived)), 7777, 9999) As OnHand  "

 

I can return 9999 if there is a value, but it returns Null if there is not a value instead of 7777.......

 

HELP

  • *Experts*
Posted

Did you mean to have a SUM() around the QtyOrdered field? You didn't show it in your first post. If you don't, then you don't need the group by.

If you DID want the sum, then try this (you can change it back to a string, but make sure the query runs fine by itself first)

 

Select tblSalesOrderDetails.ItemID, 
IsNull(SUM(tblSalesOrderDetails.QtyOrdered), 0) AS [QtyOrdered]
FROM tblSalesOrderDetails 
WHERE tblSalesOrderDetails.LineStatus = 'Closed' 
GROUP BY tblSalesOrderDetails.ItemID

 

I added an alias on the IsNull(SUM...) otherwise that column won't have a name. I gave it the same name as the column, though you may want to change that.

 

The major change above from the other suggestion is that I didn't use the IIF() -- just the IsNull. IsNull should take two params: If the first is NOT null it returns that value otherwise it returns the second value. If that format isn't supported, try COALESCE

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

It's a bad idea to use functions in the SQL-statements. Changing the database might ruin your code.

 

I prefer using txtQty.text=MyRow.Item(2).ToString

If the value in the table is null then it will be converted to '', if it's not you'll get the value as a string.

 

Good luck

/Kejpa

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...