how to access the string containing "=" and "AND" operator in where clause in oracle - sql

My query is like but it' not working and giving error "SQL command not properly ended" and the string:HDR.TRX_DT = DTL.TRX_DT AND HDR.BU_TYPE = DTL.BU_TYPE AND HDR.BU_CODE = DTL.BU_CODE
AND HDR.TRX_NO = DTL.TRX_NO AND HDR.RGSTR_NO = DTL.RGSTR_NO AND HDR.TRX_TYP_CD in ('COS') is value in column . i want use that value in where clause of select statement .How will do you that .plz suggest
select * from mdbat.migration_ctrl_all where addition_condition='HDR.TRX_DT = DTL.TRX_DT AND HDR.BU_TYPE = DTL.BU_TYPE AND HDR.BU_CODE = DTL.BU_CODE
AND HDR.TRX_NO = DTL.TRX_NO AND HDR.RGSTR_NO = DTL.RGSTR_NO AND HDR.TRX_TYP_CD in ('COS')';

Escape the ' delimiting the COS string, as said by Alex Larionow. But escape each one with another '
select * from mdbat.migration_ctrl_all where addition_condition='HDR.TRX_DT = DTL.TRX_DT AND HDR.BU_TYPE = DTL.BU_TYPE AND HDR.BU_CODE = DTL.BU_CODE
AND HDR.TRX_NO = DTL.TRX_NO AND HDR.RGSTR_NO = DTL.RGSTR_NO AND HDR.TRX_TYP_CD in (''COS'')';

Related

java.sql.SQLException: [SQL0104] Token <END-OF-STATEMENT> was not valid. Valid tokens: ) OR

I am facing SQL exception while running below query in db2 database.
UPDATE TRINITI.T_PARENT_LOTS_API
SET ACTION_CODE = TXN_CODE19_18_FROP4000_TO4000.TXN_CODE19_18_FROP4000_TO4000_TMDV_TXN_CMD,
NEW_FACTORY_NAME = TXN_CODE19_18_FROP4000_TO4000.TXN_CODE19_18_FROP4000_TO4000_TMDV_SHIP_TO_CD,
OLD_OPERATION = '' '',
NEW_OPERATION = '' '',
NEW_TXN_QTY = TXN_CODE19_18_FROP4000_TO4000.TXN_CODE19_18_FROP4000_TO4000_TMDV_TXN_QTY2,
TRANSFER_FACTORY_NAME = TXN_CODE19_18_FROP4000_TO4000.TXN_CODE19_18_FROP4000_TO4000_TMDV_TRANSFER_FACTORY_NAME,
SUBINV_CODE = TXN_CODE19_18_FROP4000_TO4000.TXN_CODE19_18_FROP4000_TO4000_TMDV_SUBINV_CODE,
TRANSFER_SUBINV_CODE = TXN_CODE19_18_FROP4000_TO4000.TXN_CODE19_18_FROP4000_TO4000_TMDV_TRANSFER_SUBINV_CODE,
NEW_BOM_LEVEL = '' DBK '',
NEW_UOM_CODE = TXN_CODE19_18_FROP4000_TO4000.UOM
Where TRINITI.T_PARENT_LOTS_API.ACTION_CODE Is null
And ((TRINITI.T_PARENT_LOTS_API.OLD_STATE_ID = '18' And
TRINITI.T_PARENT_LOTS_API.NEW_OPERATION = '4000' And
TRINITI.T_PARENT_LOTS_API.OLD_OPERATION = '4000' And
TRINITI.T_PARENT_LOTS_API.COMMENTS = 'SHIP')
Or (TRINITI.T_PARENT_LOTS_API.OLD_STATE_ID = '19'
And TRINITI.T_PARENT_LOTS_API.NEW_OPERATION = '4000'
And TRINITI.T_PARENT_LOTS_API.COMMENTS = 'RECV')
)
And TRINITI.T_PARENT_LOTS_API.TRANSACTION_ID = TXN_CODE19_18_FROP4000_TO4000.CONTROL_NO
Not getting where query went wrong.
SQL0104N is a syntax error. It says it is expecting another ")" somewhere. Looking at your statement, count how many "(" you open and how many closing ")" you have. That seems correct. Now, because Db2 complains about end of statement, you need to check if the statement is really passed to Db2 as given above.
Is there an additional character or formatting that indicates "end of statement"?

Data Type mismatch in criteria expression when Table Adapter Update

I have already been searched solution and can't get the right solution yet.
ObjDRow = DataDataSet.Client.Rows.Find(strClientNo)
With ObjDRow
.ClientName = txtClientName.Text.Trim
.ClientAddr = txtAddr.Text.Trim
If txtRegOffice.Text = "" Then
.ClientRegOfficeAddr = txtAddr.Text.Trim
Else
.ClientRegOfficeAddr = txtRegOffice.Text.Trim
End If
.MailtoCorresAddr = RBtnCorresAddr.Checked
.MailtoRegOffice = RBtnRegOffice.Checked
.ClientHPhone = mskHandPhone.Text.Trim
.ClientPager = mskPagerNo.Text.Trim
.ClientTel = mskTelephone.Text.Trim
.ClientFaxNo = mskFax.Text.Trim
.ClientEmail = txtEmail.Text.Trim
.PrimaryPartner = txtPriPartner.Text.Trim
.SecondPartner = txtSecPartner.Text.Trim
.BroughtInBy = cboPreferredBy.Text.Trim
.PersonIncharge = cboPersonIncharge.Text.Trim
.GLAC = cboGLAcode.Text.Trim
.ContactPerson = txtContactPerson.Text.Trim
.AcraNo = txtAcraNo.Text.Trim
.Active = chkActive.Checked
If dtpfyear.Checked = True Then
.YearEnd = dtpfyear.Text
End If
.DeptNo = cboDeptNo.Text.Trim
.DateJoined = dtDateJoined.Value
If cboClientName.SelectedIndex = -1 Then
.Group = txtClientNo.Text
Else
.Group = cboClientName.SelectedValue
End If
.GroupStatus = RButtonMainYes.Checked
.MainGroup = RButtonSubYes.Checked
If IsDate(dtIncorporationDate.Text) Then
.DateOfIncorporation = dtIncorporationDate.Text
Else
.SetDateOfIncorporationNull()
End If
End With
ObjDRow.EndEdit()
ClientTableAdapter.Update(DataDataSet.Client)
Error is occurs when ClientTableAdapter Update.
This error occurs for some client only.
I already check datatype of database and table adapter's datatype and all datatype are same.
My input value datatype and table adapter's datatype are same.
This error occurs even I command all line of update code (.ClientName to last line) but this error still occurs.WTF
Most answers say this is a single quote problem but In my case, There is no single quote.
All data types are same and input values are the same with datatype.
** Updated**
This error still occurs even I do like=>
ObjDRow = DataDataSet.Client.Rows.Find(strClientNo)
ObjDRow.EndEdit()
ClientTableAdapter.Update(DataDataSet.Client)
There is nothing change just select and update.
But if I remove ObjDRow.EndEdit().All are fine. There is no error.

Creating a multiple query

I would like to run 2 queries within the same code, but I cannot figure out how to. The 2 queries are as follows:
UPDATE usercomp
SET shiftstart = shifts.shiftstarttime,
shiftfinish = shifts.shiftfinishtime
FROM shifts
WHERE usercomp.shiftid = shifts.id
SET break1start = breaks.timestarted,
break1finish = breaks.timefinished,
break1duration = breaks.duration
FROM breaks
WHERE usercomp.break1id = breaks.id;
I am getting the following error:
ERROR: syntax error at or near "SET"
LINE 6: SET break1start = breaks.timestarted,
Can anyone help ?
You need to write two UPDATE statement
UPDATE usercomp
SET shiftstart = shifts.shiftstarttime,
shiftfinish = shifts.shiftfinishtime
FROM shifts
WHERE usercomp.shiftid = shifts.id;
UPDATE usercomp
SET break1start = breaks.timestarted,
break1finish = breaks.timefinished,
break1duration = breaks.duration
FROM breaks
WHERE usercomp.break1id = breaks.id;

Get Where Condition From SQL Query in java

how can i get exact Condition From SQL Query like below :
select * from users where name = "ned stark" order by id ;
select * from users where name = "rob stark" group by id ;
i want to get ' name = "ned stark" ' and ' name = "rob stark" ';
is there way to do this ?
You can solve your problem using simply substring:
String aa = "select * from test where a='aa' and b='bb' order by aa";
int startIndext = aa.indexOf("where") + 5;
int endIndex = aa.indexOf("group");
if(endIndex<0) endIndex = aa.indexOf("order");
if(endIndex<0) endIndex = aa.length();
String whereCondition = aa.substring(startIndext, endIndex);
System.out.println("whereCondition: " + whereCondition);

Where clause on dynamic column name in LINQ query?

I've created a dropdown with some column names in a table in my db. When a user selects a column name i want to add a where clause to the query to use this filter.
What i'm trying to do is:
Dim objQuery = (From wc In _dbBellen.dealer_telefonies Order By wc.Bedrijfsnaam Select wc)
'if dropdown has value...
objQuery = objQuery.Where(Function(wc) wc.DynamicColumnName < txtFilterValue1.Text)
The wc.DynamicColumnName has to be replaced by for example wc.Price.
--
The code what i'm tried now after some replies is:
Dim objQuery = (From wc In _dbBellen.dealer_telefonies Order By wc.Bedrijfsnaam Select wc)
If ddlFilterColumn1.SelectedValue <> "" And ddlFilterOperator1.SelectedValue <> "" And txtFilterValue1.Text <> "" Then
Select Case ddlFilterOperator1.SelectedValue
Case "..%"
objQuery = objQuery.Where(Function(wc) wc.WHMCSClient_id Like txtFilterValue1.Text & "%")
Case "%.."
objQuery = objQuery.Where(Function(wc) wc.WHMCSClient_id Like "%" & txtFilterValue1.Text)
Case Else '< > = <>
'objQuery = objQuery.Where(Function(wc) wc.WHMCSClient_id < txtFilterValue1.Text)
'objQuery = objQuery.Where(Function(wc) "wc." + ddlFilterColumn1.SelectedValue.ToString + " < " + txtFilterValue1.Text)
objQuery = objQuery.Where(Function(wc) "wc.WHMCSClient_id < 500")
End Select
End If
Response.Write(objQuery.ToString())
But i am getting the following error (original error is in dutch but it said as follow):
The conversion from string wc.WHMCSClient_id < 500 to type Boolean is invalid.
This is quite an old article, but I think it's still viable
Scott Gu posted about the Dynamic LINQ library a while back which essentially allows you to use strings to query collections in a "LINQ"-type format., i.e. something like this:
Dim objQuery = (From wc In _dbBellen.dealer_telefonies Order By wc.Bedrijfsnaam Select wc)
// if dropdown has value...
Dim result = objQuery.Where("MyColumnName < " + txtFilterValue1.Text);
Here's a link to the full article: Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)