Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


database connection string

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59521
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> database connection string
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 database connection string - 4/25/2008 9:38:39 AM   
  cdiltz

 

Posts: 3
Score: 0
Joined: 4/21/2008
Status: offline
I have a string connection in my script to an ODBC connection. 
I want to multiply two fields in my connection string to return results.
One of the fields is a text (char) field and I need to convert this to complete the calculation.

I have tested my syntax in SQL but I cannot get the vbScript to run.  It gives the common
elexical element not found.  Here is the connection string.


'strSQL = "SELECT Sum(CASE when CI_Item.ShipWeight = ' ' then 0" & _
'"when CI_Item.ShipWeight > 0 Then (Cast(CI_Item.ShipWeight as Numeric)*(SO_SalesOrderDetail.QuantityOrdered))+0 " & _
'"when CI_Item.ShipWeight < 0 Then (Cast(CI_Item.ShipWeight as Numeric)*(SO_SalesOrderDetail.QuantityOrdered))+0 " & _
'"when CI_Item.ShipWeight = 0 Then 0 " & _
'"when CI_Item.ShipWeight = Null Then 0 " & _
'"Else 0 End) as TotalQuantity FROM SO_SalesOrderDetail, CI_Item " & _
"where SO_SalesOrderDetail.ItemCode = CI_Item.ItemCode " & _
'" and (((SO_SalesOrderDetail.SalesOrderNo)='"+ SO_SalesOrder_bus_SalesOrderNo +"'))"

'objRS.open strSQL, objConn

'TotalQty = trim(objRS.fields.Item("TotalQuantity").value)




 
 
Post #: 1
 
 RE: database connection string - 4/25/2008 4:22:32 PM   
  ehvbs

 

Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi cdiltz,

(1) what you showed isn't a connection string, but an SQL statement; if this is just
     a kind of typo and you can connect to your DB and execute simple statements
     ignore (1); otherwise post more of your code

(2) if your

       'strSQL = "SELECT S...

    (mark the ') isn't a copy & paste artefact, remove the ' and try again

(3) if (2) helps, double check your statement, e.g.

    ... then 0" & _
    '"when CI_Item.ShipWeight ...

    will result in ... then0when ...

Good luck!

ehvbs

(in reply to cdiltz)
 
 
Post #: 2
 
 RE: database connection string - 4/28/2008 3:04:41 AM   
  cdiltz

 

Posts: 3
Score: 0
Joined: 4/21/2008
Status: offline
Here is all my my code.  I reviewed for spaces, etc and still get a element not found message.
I have set a value for a string variable called strCASE which is inserted into the strSQL statement.
This is set inside a much larger script that declares and passes other values like 
SO_SalesOrder_bus_SalesOrderNo. 

I created a message box when I run my script to look at the strCASE and strSQL once they are
put together.  It all looks good.  So I'm wondering if I'm failing on the CAST language or using
the CASE statement. 


  '*********************************************
  'Set Value - - > TotalWeight
  '
  '*********************************************
  Dim strCASE, TotalQty, TotalWeight, SO_SalesOrder_bus_SalesOrderNo
  TotalWeight = 0
  TotalQty = 0
  SO_SalesOrder_bus_SalesOrderNo = '9998'

  strCASE = "'Total' = CASE"& chr(13) & _
  "when CI_Item.ShipWeight = '' then 0 " & chr(13) & _
   "when CI_Item.ShipWeight > 0 Then (Cast(CI_Item.ShipWeight as Numeric)*(SO_SalesOrderDetail.QuantityOrdered))+0 " & _
  "when CI_Item.ShipWeight < 0 Then (Cast(CI_Item.ShipWeight as Numeric)*(SO_SalesOrderDetail.QuantityOrdered))+0 " & _
   "when CI_Item.ShipWeight = 0 Then 0 " & chr(13) & _
  "when CI_Item.ShipWeight = Null Then 0 " & chr(13) & _
  "Else 0 End" & chr(13)
  
  MsgBox(strCASE)

  strSQL = "SELECT Sum("& chr(13)& strCASE & chr(13)& ") as TotalQuantity FROM SO_SalesOrderDetail, CI_Item where SO_SalesOrderDetail.ItemCode = CI_Item.ItemCode " & _
  " and (((SO_SalesOrderDetail.SalesOrderNo)='"+ SO_SalesOrder_bus_SalesOrderNo + "'))"

  MsgBox("String: " & strSQL)

  objRS.open strSQL, objConn

  TotalQty = trim(objRS.fields.Item("TotalQuantity").value)

  If TotalQty <> 0 Then
  TotalWeight = TotalQty    
  Else TotalWeight = 0
  End If

  objRS.Close

< Message edited by cdiltz -- 4/28/2008 3:06:10 AM >

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: database connection string - 4/28/2008 3:09:02 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
If this is all of your code then I don't see anywhere that you create objRS or objConn

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cdiltz)
 
 
Post #: 4
 
 RE: database connection string - 4/28/2008 4:17:15 AM   
  cdiltz

 

Posts: 3
Score: 0
Joined: 4/21/2008
Status: offline
I create those objects in the code prior to that.  It's alot of code, but below is all of my VBS file.

Please search down to section:   'Set Value - - > TotalWeight


      


EDIT - EBGREEN - Code tags are fun.

< Message edited by ebgreen -- 4/30/2008 1:45:02 AM >

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: database connection string - 4/30/2008 1:47:40 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
This line:

SO_SalesOrder_bus_SalesOrderNo = '9998'

is syntactically incorrect. Try:

SO_SalesOrder_bus_SalesOrderNo = "'9998'"

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cdiltz)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> database connection string Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts