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
10 1972
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
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.
Just found your other post relating to this so I put an answer there also.
Hope it helps
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
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
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.
also this isn't correct in the field selection section -
Cust_Org_Name = CASE WHEN C.CustomerType ='I' THEN RTRIM(CL.Lastname)WHEN C.CustomerType = 'E' THEN RTRIM(CL.Customername)END
-
it should like this -
CASE WHEN C.CustomerType ='I' THEN RTRIM(CL.Lastname)WHEN C.CustomerType = 'E' THEN RTRIM(CL.Customername)END as Cust_Org_Name
-
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. -
Declare @String as nVarChar(1000)
-
-
Declare @Ind as Char(1),@Com as Char(1),@BAC3 as Char(1)
-
Declare @BAC1 as Char(1),@BAC2 as Char(1),@BAC4 as Char(1)
-
Declare @current as varChar(7),@saving as varChar(6)
-
Declare @move as varChar(12),@Other as varChar(5)
-
Declare @new as varChar(3),@old as varChar(3),@back as varChar(10)
-
-
set @Ind = 'I'
-
set @Com = 'E'
-
set @BAC1 = 'C'
-
set @BAC2 = 'S'
-
set @BAC3 = 'M'
-
set @BAC4 = 'O'
-
set @current = 'Current'
-
Set @saving = 'Saving'
-
Set @move = 'Money Market'
-
SET @Other = 'Other'
-
Set @new = 'NEW'
-
Set @old = 'OLD'
-
Set @back = 'BACKORDER'
-
-
-
SELECT D.TransactionType,TransactionId,T.TransactionDate, T.TransactionAmount As GrandTotal,TransactionQuantity As AmtDtl,
-
TransactionConversionRate As Convrate,AC.Country As CustCtry,AP.Parish As CustPsh,AD.District AS CustDst,AM.Community As CustCom,CL.Street As CustSrt,
-
TransactionNotes,CL.Occupation,CL.TaxRegistrationN umber As Cust_Trn,AG.Firstname As AgentFname,
-
AG.LastName As AgentLname,SUBSTRING(AG.Middlename,1,1) As AgentMI,IT.EmploymentJobTitle As Title,AG.TaxRegistrationNumber As AgentTrn,
-
AG.TelephoneNumbers As AgentPhone,CL.TelephoneNumbers As CustPhone,T.BeneficiaryCustomerCode As Cust_no,TransactionNotes As SourceOfFunds,
-
AC2.Country As AgntCtry,AP2.Parish As AgntPsh,AD2.District AS AgntDst,AM2.Community As AgntCom,AG.Street As AgntSrt,CL.CustomerCode As AgentCode,
-
Cust_Org_Name = CASE WHEN C.CustomerType ='I' THEN RTRIM(CL.Lastname)WHEN C.CustomerType = 'E' THEN RTRIM(CL.Customername)END,
-
CL.Firstname,C2.CustomerIdentificationTypeDesc ription As AgentID,
-
AG.DocumentNumber As AgentDocNum,
-
T.DocumentNumber,C.CustomerIdentificationTypeDescr iption As ClientID,RTRIM(CurrencyAbbreviation) As CurDesc,RTRIM(InstrumentDescription) As InsDesc,TransactionTradeRate As ExRate
-
,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
-
,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,
-
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,
-
Substring(Cast(T.DateTimeCreated as Char(24)),12,8) As tranTime,CL.DateOfBirth As Dob
-
FROM Customer AG RIGHT OUTER JOIN TradeTransactions T ON AG.CustomerCode = T.BeneficiaryCustomerCode
-
LEFT OUTER JOIN BankTransactionSummary BT
-
ON BT.OriginatingTransactionNumber = T.TransactionId
-
LEFT OUTER JOIN InventoryBank IB
-
ON IB.InventoryBankCode = BT.InventoryBankCode
-
,TradeTransactionsDetails D,CustomerIdentificationType C,CustomerIdentificationType C2,Customer CL,Currency CR,Instruments I,
-
SysAddressCountry AC,SysAddressCountry AC2,SysAddressParish AP,SysAddressParish AP2,SysAddressDistrict AD,SysAddressDistrict AD2,
-
SysAddressCommunity AM,SysAddressCommunity AM2,InventoryTraders IT,CustomerCategory CC
-
WHERE C.CustomerIdentificationTypeCode = IdentificationUsed AND CR. CurrencyCode = D.CurrencyCode AND Liquidity = 1
-
AND I.InstrumentCode = D.InstrumentCode AND D.CurrencyCode <> 1 AND VoidedByUser IS NULL
-
AND CL.CustomerCode = T.Customer AND T.TransactionId = TransactionNumber
-
AND I.CompanyCode = @Company And I.LocationCode = @Location AND I.BranchCode = @Branch
-
AND CR.CompanyCode = @Company And CR.LocationCode = @Location AND CR.BranchCode = @Branch
-
AND D.TransactionType <> 'BackOrder' AND D.TransactionType = T.TransactionType
-
AND AC.CountryCode = CL.Country AND AP.ParishCode = CL.ParishOrState AND AD.DistrictCode = CL.DistrictOrCity AND CC.Include_In_Money_Laudering_Report = 1
-
AND AM.CommunityCode = CL.CommunityOrTownShip AND IT.TradersCode = T.TraderCode
-
AND AC2.CountryCode = AG.Country AND AP2.ParishCode = AG.ParishOrState AND AD2.DistrictCode = AG.DistrictOrCity
-
AND AM2.CommunityCode = AG.CommunityOrTownShip AND C2.CustomerIdentificationTypeCode = AG.CustomerIdentificationType AND CC.CompanyCode = @Company
-
AND T.CompanyCode = @Company AND T.LocationCode = @Location AND T.BranchCode = @Branch AND CC.CustomerCategoryCode = AG.CustomerCategory
-
AND D.CompanyCode = @Company AND D.LocationCode = @Location AND D.BranchCode = @Branch
-
order by Cust_no, trantime ASC,CurDesc
-
Delerna suppose i want to place the slection in a temp table where would i put the INSERT INTO #TEMP
INSERT INTO #TEMP
SELECT.....the rest of the query
Does that make sense
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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);
|
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...
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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: 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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |