473,480 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Syntax Error

10 New Member
Expand|Select|Wrap|Line Numbers
  1. Declare @String as nVarChar(1000)
  2.  
  3. Declare @Ind as Char(1),@Com as Char(1),@BAC3 as Char(1)
  4. Declare @BAC1 as Char(1),@BAC2 as Char(1),@BAC4 as Char(1)
  5. Declare @current as varChar(7),@saving as varChar(6)
  6. Declare @move as varChar(12),@Other as varChar(5)
  7. Declare @new as varChar(3),@old as varChar(3),@back as varChar(10)
  8.  
  9. set @Ind = 'I'
  10. set @Com = 'E'
  11. set @BAC1 = 'C' 
  12. set @BAC2 = 'S'
  13. set @BAC3 = 'M'
  14. set @BAC4 = 'O'
  15. set @current = 'Current'
  16. Set @saving = 'Saving'
  17. Set @move = 'Money Market'
  18. SET @Other = 'Other'
  19. Set @new = 'NEW'
  20. Set @old = 'OLD'
  21. Set @back = 'BACKORDER'
  22.  
  23.  
  24. SET @String = 'SELECT D.TransactionType,TransactionId,T.TransactionDate,T.TransactionAmount As GrandTotal,
  25. TransactionQuantity As AmtDtl,
  26. TransactionConversionRate As Convrate,AC.Country As CustCtry,AP.Parish As CustPsh,AD.District AS CustDst,AM.Community As CustCom,CL.Street As CustSrt,
  27. TransactionNotes,CL.Occupation,CL.TaxRegistrationNumber As Cust_Trn,AG.Firstname As AgentFname,
  28. AG.LastName As AgentLname,SUBSTRING(AG.Middlename,1,1) As AgentMI,IT.EmploymentJobTitle As Title,AG.TaxRegistrationNumber As AgentTrn,
  29. AG.TelephoneNumbers As AgentPhone,CL.TelephoneNumbers As CustPhone,T.BeneficiaryCustomerCode As Cust_no,TransactionNotes As SourceOfFunds,
  30. AC2.Country As AgntCtry,AP2.Parish As AgntPsh,AD2.District AS AgntDst,AM2.Community As AgntCom,AG.Street As AgntSrt,CL.CustomerCode As AgentCode,
  31. Cust_Org_Name =
  32. CASE WHEN C.CustomerType ='+'I'+'THEN RTRIM(CL.Lastname)
  33. WHEN C.CustomerType = '+'E'+'THEN RTRIM(CL.Customername)
  34. END,CL.Firstname,C2.CustomerIdentificationTypeDescription As AgentID,AG.DocumentNumber As AgentDocNum,
  35. T.DocumentNumber,C.CustomerIdentificationTypeDescription As ClientID,RTRIM(CurrencyAbbreviation) As CurDesc,RTRIM(InstrumentDescription) As InsDesc,TransactionTradeRate As ExRate
  36. ,CustKnown =
  37. CASE WHEN CL.DateTimeCreated > (SELECT TOP 1 GenDateTime FROM TradeThresholdReport WHERE CompanyCode = @Company AND LocationCode = @Location AND BranchCode = @Branch ORDER BY GenDateTime DESC ) THEN'+ 'NEW'+'
  38. ELSE '+'OLD'+' 
  39. END,BankAccountNumber
  40. ,AgentKnown = 
  41. CASE WHEN AG.DateTimeCreated > (SELECT TOP 1 GenDateTime FROM TradeThresholdReport WHERE CompanyCode = @Company AND LocationCode = @Location AND BranchCode = @Branch ORDER BY GenDateTime DESC ) THEN '+ 'NEW'+'
  42. ELSE '+ 'OLD'+'
  43. END,
  44. AccountType = 
  45. CASE WHEN IB.BankAccountType = '+'C'+' THEN '+'Current'+'
  46. WHEN IB.BankAccountType = '+'S'+' THEN '+'Saving'+'
  47. WHEN IB.BankAccountType = '+'M'+' THEN '+'Money Market'+'
  48. WHEN IB.BankAccountType = '+'O'+' THEN  '+'Other'+'
  49. END,Substring(Cast(T.DateTimeCreated as Char(24)),12,8) As tranTime,CL.DateOfBirth As Dob
  50. FROM Customer AG RIGHT OUTER JOIN TradeTransactions T  ON AG.CustomerCode = T.BeneficiaryCustomerCode
  51. LEFT OUTER JOIN BankTransactionSummary BT
  52. ON BT.OriginatingTransactionNumber = T.TransactionId
  53. LEFT OUTER JOIN InventoryBank IB
  54. ON IB.InventoryBankCode = BT.InventoryBankCode
  55. ,TradeTransactionsDetails D,CustomerIdentificationType C,CustomerIdentificationType C2,Customer CL,Currency CR,Instruments I,
  56. SysAddressCountry AC,SysAddressCountry AC2,SysAddressParish AP,SysAddressParish AP2,SysAddressDistrict AD,SysAddressDistrict AD2,
  57. SysAddressCommunity AM,SysAddressCommunity AM2,InventoryTraders IT,CustomerCategory CC
  58. WHERE C.CustomerIdentificationTypeCode = IdentificationUsed AND CR. CurrencyCode = D.CurrencyCode AND Liquidity = 1
  59. AND I.InstrumentCode = D.InstrumentCode AND D.CurrencyCode <> 1 AND VoidedByUser IS NULL
  60. AND CL.CustomerCode  = T.Customer  AND T.TransactionId = TransactionNumber
  61. AND I.CompanyCode    = @Company  And I.LocationCode  = @Location   AND I.BranchCode  = @Branch
  62. AND CR.CompanyCode   = @Company  And CR.LocationCode = @Location   AND CR.BranchCode = @Branch
  63. AND D.TransactionType <> '+'BackOrder'+' AND D.TransactionType = T.TransactionType
  64. AND AC.CountryCode   = CL.Country AND AP.ParishCode = CL.ParishOrState AND AD.DistrictCode = CL.DistrictOrCity AND CC.Include_In_Money_Laudering_Report = 1
  65. AND AM.CommunityCode = CL.CommunityOrTownShip AND IT.TradersCode = T.TraderCode
  66. AND AC2.CountryCode  = AG.Country AND AP2.ParishCode = AG.ParishOrState AND AD2.DistrictCode = AG.DistrictOrCity
  67. AND AM2.CommunityCode = AG.CommunityOrTownShip AND C2.CustomerIdentificationTypeCode = AG.CustomerIdentificationType AND CC.CompanyCode = @Company
  68. AND T.CompanyCode    = @Company AND T.LocationCode = @Location AND T.BranchCode = @Branch AND CC.CustomerCategoryCode = AG.CustomerCategory
  69. AND D.CompanyCode    = @Company AND D.LocationCode = @Location AND D.BranchCode = @Branch 
  70. order by Cust_no, trantime ASC,CurDesc'
  71. --print @String
  72.  
  73. --set @String = 'Select * from TradeTransactionsDetails'
  74.  
  75. Exec(@String) 
  76.  
I am getting a syntax error at RTRIM(CL.FirstName) can some one tell me why
Feb 4 '08 #1
5 1279
ck9663
2,878 Recognized Expert Specialist
what error was it?

-- ck
Feb 4 '08 #2
allik7
10 New Member
Incorrect Syntax at RTRIM copy and paste it in query and you will see the error
thanks in advance
Feb 4 '08 #3
Delerna
1,134 Recognized Expert Top Contributor
you need to put a space between the ' and the THEN
that comes just before RTRIM(CL.FirstName)
Feb 4 '08 #4
Delerna
1,134 Recognized Expert Top Contributor
you will also need to add a + char(39) + either side of I and E so that you can get the strin quote into the string

This bit
CASE WHEN C.CustomerType ='+'I'+'THEN RTRIM(CL.Lastname)
will appear in your string as
CASE WHEN C.CustomerType =ITHEN RTRIM(CL.Lastname)

where as you need it to be
CASE WHEN C.CustomerType ='I' THEN RTRIM(CL.Lastname)

so this will do it
CASE WHEN C.CustomerType =' + char(39) + 'I' + char(39) + ' THEN RTRIM(CL.Lastname)
Feb 4 '08 #5
ck9663
2,878 Recognized Expert Specialist
i'd assume delarna is right and will not paste the whole code...

also try this:

CASE WHEN C.CustomerType = '+'I'+' THEN RTRIM(CL.Lastname)

i just added space between the single-quote and equal sign and another space between single-quote and THEN...

-- ck
Feb 5 '08 #6

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

Similar topics

1
3328
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
1
3218
by: Donald Canton | last post by:
Hi, I'm using Bjarne's book to learn C++ and am stuck on the Calc program in Section 6. Everything works fine except when I try to use istringstream to parse a token from the command line. I...
5
4469
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
2
2243
by: david | last post by:
Anyone could give me a hand about this syntax error? Thank you. David Source Code: Dim conn As New SqlConnection(strConn) Dim daAngio As New SqlDataAdapter(strSelectStatement, conn) 'Create a...
3
16186
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
1
2209
by: Hari Sekhon | last post by:
I've written an except hook into a script as shown below which works well for the most part and catches exceptions. import sys def myexcepthook(type,value,tb): do something ...
7
1820
by: Josh | last post by:
I have a lot of except Exception, e statements in my code, which poses some problems. One of the biggest is whenever I refactor even the triviallest thing in my code. I would like python to...
7
2860
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",...
6
37995
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
5
4001
Banfa
by: Banfa | last post by:
So I have a little problem, I have a template class and that class contains a template function; now what I want to do is declare that function in the class (or indeed the entire class) as a friend...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.