473,396 Members | 2,002 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,396 software developers and data experts.

Syntax error in the case statment

10
I am have a problem with this section of code. When I place the select statemnet in a string variable i get an syntax error at RTRIM. Can the Case section be used in a string variable i am wondering

Cust_Org_Name =
CASE WHEN C.CustomerType ='+'I'+'THEN RTRIM(CL.Lastname)
WHEN C.CustomerType = '+'E'+'THEN RTRIM(CL.Customername)
END,

Thanks for your assistance
Feb 4 '08 #1
10 1972
Delerna
1,134 Expert 1GB
One thing that stands out.
I think this ...'THEN... should be this ...' THEN... ie you need a space between ' and THEN because the above code comes out as

CASE WHEN C.CustomerType =ITHEN RTRIM(CL.Lastname) WHEN C.CustomerType = ETHEN RTRIM(CL.Customername) END,

There is no such command as ITHEN or ETHEN and therefore you get a syntax error
Feb 4 '08 #2
Delerna
1,134 Expert 1GB
Oh, and there is no reason you can't do what you are trying to do.
The info you provide leaves a bit puzzled at what you are doing but there is enough info to show that you are not trying to do something that can't be done.
Feb 4 '08 #3
Delerna
1,134 Expert 1GB
Just found your other post relating to this so I put an answer there also.
Hope it helps
Feb 4 '08 #4
allik7
10
I did what u said i should do and the error went somewhere else the error now look like this
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "D.TransactionType" could not be bound.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'TransactionId'.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "T.TransactionDate" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "T.TransactionAmount" could not be bound.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'TransactionQuantity'.
Msg 207, Level 16, State 1, Line 3

and the fields are valid. What could be the problem
Feb 4 '08 #5
Delerna
1,134 Expert 1GB
that means we fixed the first problem and now there are more.
Ill go to your other post and have a look at the full code there
Feb 5 '08 #6
Delerna
1,134 Expert 1GB
Can I ask why you are using a dynamic query.
At first glance I can't see any reason why you shouldnt be using a regular query.

Another problem I see is that you can't referece a variable in a dynamic SQL string that is declared outside of the string.

Its also quite a large query, maybe youve gone over the 1000 characters you declared the string variable as.

also there are quite a lot of instances where you will need to add the + char(38) + in order to get the ' into the string.

I suggest you try copying the query into another query analyser window and change it into a regular query. It will be much easier to find the errors.

Unless of course there is a valid reason for it being dynamic.
Feb 5 '08 #7
Delerna
1,134 Expert 1GB
also this isn't correct in the field selection section
Expand|Select|Wrap|Line Numbers
  1. Cust_Org_Name = CASE WHEN C.CustomerType ='I' THEN RTRIM(CL.Lastname)WHEN C.CustomerType = 'E' THEN RTRIM(CL.Customername)END
  2.  
it should like this
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN C.CustomerType ='I' THEN RTRIM(CL.Lastname)WHEN C.CustomerType = 'E' THEN RTRIM(CL.Customername)END as Cust_Org_Name
  2.  
Feb 5 '08 #8
Delerna
1,134 Expert 1GB
Here is your query as a standard query as best I could.
I may have missed a few things.
I have a feeling that this query is going to be quite slow due to there being subqueries in the selection fields, for example lines 34 and 35.

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. SELECT D.TransactionType,TransactionId,T.TransactionDate, T.TransactionAmount As GrandTotal,TransactionQuantity As AmtDtl,
  25.         TransactionConversionRate As Convrate,AC.Country As CustCtry,AP.Parish As CustPsh,AD.District AS CustDst,AM.Community As CustCom,CL.Street As CustSrt,
  26.         TransactionNotes,CL.Occupation,CL.TaxRegistrationN umber As Cust_Trn,AG.Firstname As AgentFname,
  27.         AG.LastName As AgentLname,SUBSTRING(AG.Middlename,1,1) As AgentMI,IT.EmploymentJobTitle As Title,AG.TaxRegistrationNumber As AgentTrn,
  28.         AG.TelephoneNumbers As AgentPhone,CL.TelephoneNumbers As CustPhone,T.BeneficiaryCustomerCode As Cust_no,TransactionNotes As SourceOfFunds,
  29.         AC2.Country As AgntCtry,AP2.Parish As AgntPsh,AD2.District AS AgntDst,AM2.Community As AgntCom,AG.Street As AgntSrt,CL.CustomerCode As AgentCode,
  30.         Cust_Org_Name = CASE WHEN C.CustomerType ='I' THEN RTRIM(CL.Lastname)WHEN C.CustomerType = 'E' THEN RTRIM(CL.Customername)END,
  31.     CL.Firstname,C2.CustomerIdentificationTypeDesc ription As AgentID,
  32.         AG.DocumentNumber As AgentDocNum,
  33.         T.DocumentNumber,C.CustomerIdentificationTypeDescr iption As ClientID,RTRIM(CurrencyAbbreviation) As CurDesc,RTRIM(InstrumentDescription) As InsDesc,TransactionTradeRate As ExRate
  34.         ,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' ELSE 'OLD' END as CustKnown,BankAccountNumber
  35.     ,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' ELSE 'OLD' END as AgentKnown,
  36.     CASE WHEN IB.BankAccountType = 'C' THEN 'Current' WHEN IB.BankAccountType = 'S' THEN 'Saving' WHEN IB.BankAccountType = 'M' THEN 'Money Market' WHEN IB.BankAccountType = 'O' THEN 'Other'END as AccountType,
  37.     Substring(Cast(T.DateTimeCreated as Char(24)),12,8) As tranTime,CL.DateOfBirth As Dob
  38. FROM Customer AG RIGHT OUTER JOIN TradeTransactions T ON AG.CustomerCode = T.BeneficiaryCustomerCode
  39. LEFT OUTER JOIN BankTransactionSummary BT
  40. ON BT.OriginatingTransactionNumber = T.TransactionId
  41. LEFT OUTER JOIN InventoryBank IB
  42. ON IB.InventoryBankCode = BT.InventoryBankCode
  43. ,TradeTransactionsDetails D,CustomerIdentificationType C,CustomerIdentificationType C2,Customer CL,Currency CR,Instruments I,
  44. SysAddressCountry AC,SysAddressCountry AC2,SysAddressParish AP,SysAddressParish AP2,SysAddressDistrict AD,SysAddressDistrict AD2,
  45. SysAddressCommunity AM,SysAddressCommunity AM2,InventoryTraders IT,CustomerCategory CC
  46. WHERE C.CustomerIdentificationTypeCode = IdentificationUsed AND CR. CurrencyCode = D.CurrencyCode AND Liquidity = 1
  47. AND I.InstrumentCode = D.InstrumentCode AND D.CurrencyCode <> 1 AND VoidedByUser IS NULL
  48. AND CL.CustomerCode = T.Customer AND T.TransactionId = TransactionNumber
  49. AND I.CompanyCode = @Company And I.LocationCode = @Location AND I.BranchCode = @Branch
  50. AND CR.CompanyCode = @Company And CR.LocationCode = @Location AND CR.BranchCode = @Branch
  51. AND D.TransactionType <> 'BackOrder' AND D.TransactionType = T.TransactionType
  52. AND AC.CountryCode = CL.Country AND AP.ParishCode = CL.ParishOrState AND AD.DistrictCode = CL.DistrictOrCity AND CC.Include_In_Money_Laudering_Report = 1
  53. AND AM.CommunityCode = CL.CommunityOrTownShip AND IT.TradersCode = T.TraderCode
  54. AND AC2.CountryCode = AG.Country AND AP2.ParishCode = AG.ParishOrState AND AD2.DistrictCode = AG.DistrictOrCity
  55. AND AM2.CommunityCode = AG.CommunityOrTownShip AND C2.CustomerIdentificationTypeCode = AG.CustomerIdentificationType AND CC.CompanyCode = @Company
  56. AND T.CompanyCode = @Company AND T.LocationCode = @Location AND T.BranchCode = @Branch AND CC.CustomerCategoryCode = AG.CustomerCategory
  57. AND D.CompanyCode = @Company AND D.LocationCode = @Location AND D.BranchCode = @Branch 
  58. order by Cust_no, trantime ASC,CurDesc
  59.  
Feb 5 '08 #9
allik7
10
Delerna suppose i want to place the slection in a temp table where would i put the INSERT INTO #TEMP
Feb 5 '08 #10
Delerna
1,134 Expert 1GB
INSERT INTO #TEMP
SELECT.....the rest of the query

Does that make sense
Feb 5 '08 #11

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

Similar topics

2
by: MFA | last post by:
Hi All I am getting this error. Microsoft VBScript runtime (0x800A0006) Overflow: '' I am using if and case statments a lot, at certain point when I am just putting another case statment...
9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
3
by: Gizmo | last post by:
hello all have been trying to write a Mid() function a bit like the one in vb. i come to compile it and there are no errors however when i run it an error accours and it says the program has to...
1
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...
18
by: Ian Davies | last post by:
Hello Apologies for posting to so many groups but this one is difficult to catagorize precisely The following code worked fine with a connection to an Access database. However, I have changed...
2
by: sean | last post by:
Hi, I am trying to update an access database using an SQL statement, I keep getting an syntax error in update statment. I am passing in strChkBoxValue as a string value which is declared in...
15
by: Benny Raymond | last post by:
I'm confused as to how fallthrough is limited in switch. For example the following works: string switch_test = "a"; switch (switch_test) { case "a": case "b": case "c": doSomething(a);
2
by: Mangler | last post by:
I created a query in SQL that works fine but when i put it in the asp code ( with dreamweaver ) i am getting an error when viewing the page: expected end of statment... ...
4
by: LongWei | last post by:
Hi All, I have a select list in my HTML page as follows <select name="category" size="3" multiple="multiple" id="category"> <option value="Family">Family</option> <option...
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: 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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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,...

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.