473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

VB Query syntax problem

Hi All,

Can someone pls help me ...

Below is the query which i usely run in Access
Expand|Select|Wrap|Line Numbers
  1. select d.DEAL_FOLDER_STATUS,  d.VALUE_DATE, d.BUSINESS_DATE, 
  2. case
  3. when    d.BUY_SETL_TYPE_IND = 11
  4. then    'NET PEND'
  5. when    d.BUY_SETL_TYPE_IND = 12
  6. then    'NETTED  '
  7. when   d.buy_setL_type_ind = 15
  8. then    'NET AS GROSS'
  9. when   d.buy_setl_type_ind = 19
  10. then    ' NET GO GROSS'
  11. when    d.BUY_SETL_TYPE_IND = 21
  12. then    'GROSS PEND'
  13. when    d.BUY_SETL_TYPE_IND = 26
  14. then    'GROSS AGGR'
  15. when    d.BUY_SETL_TYPE_IND = 22
  16. then    'GROSS AD HOC'
  17. when    d.BUY_SETL_TYPE_IND = 29
  18. then    'GROSS   '
  19. when    d.BUY_SETL_TYPE_IND > 40
  20. then    'CLS     '
  21. ELSE  cast(d.buy_setl_type_ind as char(2))
  22. end as setl_type
  23. ,d.LEGAL_ENTITY_ID, d.CPTY_ID, c.formal_name, tm.book_area_id as trade_type
  24. ,d.BUY_CCY_ID, d.BUY_AMOUNT, d.SELL_CCY_ID, d.SELL_AMOUNT, d.DEAL_RATE, tm.acct_ccy_equiv_amt,tm.TRADE_SOURCE_ID
  25. , case 
  26.     when tm.trade_source_id = 'RMS' 
  27.        then (substr(tm.fo_deal_id,5,10))
  28.        else tm.fo_deal_id
  29.   end as fo_trade_id
  30. ,d.DEAL_FOLDER_ID, s.SETL_FOLDER_ID, tm.ndf_ind
  31. , d.FULLY_MATCHED_IND,d.INST_OK_IND, tm.portfolio_id
  32. from cpty c, cpty_legal_entity cle, deal_folder d, setl s, trade_master tm
  33. where
  34.     cle.company_id = c.company_id
  35. and cle.cpty_id = c.cpty_id
  36. and d.company_id = cle.company_id
  37. and d.legal_entity_id = cle.legal_entity_id
  38. and d.cpty_id = cle.cpty_id
  39. and c.record_state = 'V'
  40. and cle.cpty_id LIKE 'ABSA JB%'
  41. and cle.record_state = 'V'
  42. and d.record_state = 'V'
  43. and d.value_date > (substring(cast(current_timestamp as char(16)) from 1 for 8))
  44. and s.deal_folder_id = d.deal_folder_id
  45. and s.ccy_id = d.buy_ccy_id
  46. and tm.trade_id = d.trade_id
  47. and tm.trans_id = d.trade_trans_id
  48. and tm.ver_id = d.trade_ver_id
  49. order by d.value_date ,  SETL_TYPE, tm.book_area_id , d.BUY_CCY_ID , d.SELL_CCY_ID  , d.CPTY_ID 
  50.  
---------------------------------------------------------------------------------------------------------------

I want to run this query thru VB when i am trying to do this as below iam getting syntax error
--------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. MIS_Query = "select d.DEAL_FOLDER_STATUS,  d.VALUE_DATE, d.BUSINESS_DATE, case when  d.BUY_SETL_TYPE_IND = 11 then 'NET PEND' when  d.BUY_SETL_TYPE_IND = 12" _
  2. & " then    'NETTED' when  d.buy_setL_type_ind = 15 then 'NET AS GROSS' when d.buy_setl_type_ind = 19 then 'NET GO GROSS' when d.BUY_SETL_TYPE_IND = 21" _
  3. & " then 'GROSS PEND' when d.BUY_SETL_TYPE_IND = 26 then 'GROSS AGGR' when d.BUY_SETL_TYPE_IND = 22 then 'GROSS AD HOC' when d.BUY_SETL_TYPE_IND = 29" _
  4. & " then 'GROSS ' when d.BUY_SETL_TYPE_IND > 40 then    'CLS' ELSE  cast(d.buy_setl_type_ind as char(2)) end as setl_type ,d.LEGAL_ENTITY_ID, d.CPTY_ID, c.formal_name, tm.book_area_id as trade_type" _
  5. & " ,d.BUY_CCY_ID, d.BUY_AMOUNT, d.SELL_CCY_ID, d.SELL_AMOUNT, d.DEAL_RATE, tm.acct_ccy_equiv_amt,tm.TRADE_SOURCE_ID, case when tm.trade_source_id = 'RMS' " _
  6. & " then (substr(tm.fo_deal_id,5,10)) else tm.fo_deal_id end as fo_trade_id,d.DEAL_FOLDER_ID, s.SETL_FOLDER_ID, tm.ndf_ind,d.FULLY_MATCHED_IND,d.INST_OK_IND, tm.portfolio_id" _
  7. & " from cpty c, cpty_legal_entity cle, deal_folder d, setl s, trade_master tm where cle.company_id = c.company_id and cle.cpty_id = c.cpty_id and d.company_id = cle.company_id" _
  8. & " and d.legal_entity_id = cle.legal_entity_id and d.cpty_id = cle.cpty_id and c.record_state = 'V' and cle.cpty_id LIKE 'ABSA JB%' and cle.record_state = 'V'" _
  9. & " and d.record_state = 'V' and d.value_date > (substring(cast(current_timestamp as char(16)) from 1 for 8)) and s.deal_folder_id = d.deal_folder_id" _
  10. & " and s.ccy_id = d.buy_ccy_id and tm.trade_id = d.trade_id and tm.trans_id = d.trade_trans_id and tm.ver_id = d.trade_ver_id order by d.value_date " _
  11. & ",   SETL_TYPE, tm.book_area_id , d.BUY_CCY_ID , d.SELL_CCY_ID  , d.CPTY_ID"
  12.  
  13. DoCmd.RunSQL (MIS_Query)
  14.  
Is this error due to larger query...

Pls can someone pls help how to run this query it urjent.
Apr 20 '09 #1
11 2071
debasisdas
8,127 Expert 4TB
which line is throwing the error ?
Apr 20 '09 #2
Hi

Could you pls provide your email id i will just drop you a mail with all screen shots

Thanks for your prompt response
Apr 20 '09 #3
debasisdas
8,127 Expert 4TB
@harshakusam
No email please.

why not open a recordset using the query.
Apr 20 '09 #4
Expand|Select|Wrap|Line Numbers
  1. Public Function Metrics()
  2. On Error GoTo Err_Mod_MIS
  3.  
  4. Dim ftp_Date
  5. Dim LocMetrics, StrMetrics As String
  6. Dim RstMetrics As Recordset
  7. Dim MIS_Query As String
  8. MIS_Query = Str(20000)
  9.  
  10. DoCmd.SetWarnings False
  11. ftp_Date = Format(Date, "yyyymmdd")
  12. LocMetrics = DLookup("location", "tbl_location", _
  13.             "[function]='Metrics'")
  14. MsgBox LocMetrics
  15. StrMetrics = LocMetrics & "Metrics_" & ftp_Date & ".xls"
  16. MsgBox StrMetrics
  17.  
  18.  
  19. MIS_Query = "select d.DEAL_FOLDER_STATUS,  d.VALUE_DATE, d.BUSINESS_DATE, case when  d.BUY_SETL_TYPE_IND = 11 then 'NET PEND' when  d.BUY_SETL_TYPE_IND = 12" _
  20. & " then    'NETTED' when  d.buy_setL_type_ind = 15 then 'NET AS GROSS' when d.buy_setl_type_ind = 19 then 'NET GO GROSS' when d.BUY_SETL_TYPE_IND = 21" _
  21. & " then 'GROSS PEND' when d.BUY_SETL_TYPE_IND = 26 then 'GROSS AGGR' when d.BUY_SETL_TYPE_IND = 22 then 'GROSS AD HOC' when d.BUY_SETL_TYPE_IND = 29" _
  22. & " then 'GROSS ' when d.BUY_SETL_TYPE_IND > 40 then    'CLS' ELSE  cast(d.buy_setl_type_ind as char(2)) end as setl_type ,d.LEGAL_ENTITY_ID, d.CPTY_ID, c.formal_name, tm.book_area_id as trade_type" _
  23. & " ,d.BUY_CCY_ID, d.BUY_AMOUNT, d.SELL_CCY_ID, d.SELL_AMOUNT, d.DEAL_RATE, tm.acct_ccy_equiv_amt,tm.TRADE_SOURCE_ID, case when tm.trade_source_id = 'RMS' " _
  24. & " then (substr(tm.fo_deal_id,5,10)) else tm.fo_deal_id end as fo_trade_id,d.DEAL_FOLDER_ID, s.SETL_FOLDER_ID, tm.ndf_ind,d.FULLY_MATCHED_IND,d.INST_OK_IND, tm.portfolio_id" _
  25. & " from cpty c, cpty_legal_entity cle, deal_folder d, setl s, trade_master tm where cle.company_id = c.company_id and cle.cpty_id = c.cpty_id and d.company_id = cle.company_id" _
  26. & " and d.legal_entity_id = cle.legal_entity_id and d.cpty_id = cle.cpty_id and c.record_state = 'V' and cle.cpty_id LIKE 'ABSA JB%' and cle.record_state = 'V'" _
  27. & " and d.record_state = 'V' and d.value_date > (substring(cast(current_timestamp as char(16)) from 1 for 8)) and s.deal_folder_id = d.deal_folder_id" _
  28. & " and s.ccy_id = d.buy_ccy_id and tm.trade_id = d.trade_id and tm.trans_id = d.trade_trans_id and tm.ver_id = d.trade_ver_id order by d.value_date " _
  29. & ",   SETL_TYPE, tm.book_area_id , d.BUY_CCY_ID , d.SELL_CCY_ID  , d.CPTY_ID"
  30.  
  31. MsgBox MIS_Query
  32.  
  33.  
  34. DoCmd.RunSQL (MIS_Query)
  35.  
  36. DoCmd.TransferSpreadsheet acExport, 8, "MIS_Counts", StrMetrics, True, ""
  37.  
  38. Exit_Mod_MIS:
  39. DoCmd.SetWarnings True
  40.     Exit Function
  41.  
  42. Err_Mod_MIS:
  43.     MsgBox Err.Number & " - " & Err.Description
  44.     Resume Exit_Mod_MIS
  45.  
  46. End Function
Apr 20 '09 #5
In access when i run it will run without any errors but if iam using same in VB its throwing sytax error ... Can you pls look into this plsss
Apr 20 '09 #6
debasisdas
8,127 Expert 4TB
Do u know how to use ADO in VB 6 ?
Apr 20 '09 #7
Iam oracle guy .. first time iam using VB to automate some queries ....
Apr 20 '09 #8
debasisdas
8,127 Expert 4TB
try this

from project---->references------>select ADO 2.5 or higher library

they try the following code
Expand|Select|Wrap|Line Numbers
  1.  
  2.  Dim CON As New ADODB.Connection
  3.  Dim RS As New ADODB.Recordset
  4.  
  5.  Private Sub Command1_Click()
  6.  CON.Open "your connection string here" find more 
  7. rs.open con, your query
  8.  
  9.  End Sub
Apr 20 '09 #9
Iam alreay connecting my database using below code

Function RefreshODBCLinkedTables() As Boolean
On Error GoTo RefreshODBCLinkedTables_Err
Dim strTblName As String, strConn As String
Dim db As Database, rs As Recordset, tbl As TableDef

DoCmd.Hourglass True

' ---------------------------------------------
' Register ODBC database(s)
' ---------------------------------------------
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_ODBC")
With rs

While Not .EOF



DBEngine.RegisterDatabase rs("DSN"), _
"Oracle ODBC Driver for RDB", _
True, "Attributes=" & rs("Attributes") & Chr(13) _
& "Class=" & rs("class") & Chr(13) _
& "Cursor Option=" & rs("Cursor Option") & Chr(13) _
& "Description=" & rs("Description") & Chr(13) _
& "Options=" & rs("Options") & Chr(13) _
& "Schema=" & rs("Schema") & Chr(13) _
& "Server=" & rs("ServerName") & Chr(13) _
& "Translation Option=" & rs("Translation Option") & Chr(13) _
& "Transport=" & rs("Transport") & Chr(13) _
& "UserID=" & rs("UID")



strTblName = rs("LocalTableName")
strConn = "ODBC;"
strConn = strConn & "DSN=" & rs("DSN") & ";"
strConn = strConn & "APP=Microsoft Access;"
strConn = strConn & "DATABASE=" & rs("schema") & ";"
strConn = strConn & "UID=" & rs("UID") & ";"
strConn = strConn & "PWD=" & rs("PWD") & ";"
strConn = strConn & "TABLE=" & rs("ODBCTableName") & ";"



If (DoesTblExist(strTblName) = False) Then
Set tbl = db.CreateTableDef(strTblName, _
dbAttachSavePWD, rs("ODBCTableName"), _
strConn)
db.TableDefs.Append tbl
Else
Set tbl = db.TableDefs(strTblName)
tbl.Connect = strConn
tbl.RefreshLink
End If

rs.MoveNext
Wend
End With
RefreshODBCLinkedTables = True

RefreshODBCLinkedTables_End:
DoCmd.Hourglass False
Exit Function

RefreshODBCLinkedTables_Err:
MsgBox Err.Description, vbCritical, "Refresh ODBC"
DoCmd.Hourglass False
Resume RefreshODBCLinkedTables_End

End Function
Apr 20 '09 #10
debasisdas
8,127 Expert 4TB
you are connencting to oracle or access database ?

the following link might be helpful.

link
Apr 20 '09 #11
ms Access database
Apr 20 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: joemyre | last post by:
Hi everyone, What I'm trying to do is take php variables i got from user input, and pass them as the MySQL query terms. $query = "select * from ident where ".$searchtype1."=".$searchterm1."";...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
0
by: Arnold | last post by:
Hi, I'm using visual studio .NET 2003 enterprise and MySQL 5.0. I've created a database project in wich I like to create scripts for stored procedures and queries. I've created a connection...
3
by: KevLow | last post by:
Hi, Hope some kind soul can help me out here.. I'm trying to programmatically modify the column headings of a crosstab query such that it can be dynamic based on user specified period (Month...
1
by: Crash | last post by:
Hi, ..NET v1.x SP1 VS 2003 SQL Server 2000 SP3 Server 2000, XP, Server 2003 I would like to programmatically execute {possibly many} SQL Server batch scripts. Aka I have many scripts that...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
2
by: Flic | last post by:
Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice:...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.