How to Update some data in a table from another table in MS Access 2007 by checking a value from the second one? - ms-access-2007

i want to update some data from a table (ehraz) in MS_Access 2007 by another table's data by checking this condition : if tableA.siba=Table2.siba then update Table1.field1 by Table2.Field2.
i use this t-sql command in sql server and works :
update ehraz set
ehraz.B_CODEMELI =bn.B_CodeMelli ,
ehraz.B_NAME =ltrim(rtrim(cast(bn.B_Name as nvarchar(20)))) ,
ehraz.B_FAMILY =ltrim(rtrim(cast (bn.B_Family as nvarchar(30)))) ,
ehraz.B_FATHER_N = ltrim(rtrim(cast(bn.B_Father_N as nvarchar(20)))),
ehraz.B_SHENAS =ltrim(rtrim(bn.B_Shenas)) ,
ehraz.B_TAVALOD = ltrim(rtrim(cast(bn.B_Tavalod as nvarchar(15)))),
ehraz.B_MOSHTARI = ltrim(rtrim(cast(bn.B_Moshtari as nvarchar(20)))) ,
ehraz.B_BARNO = ltrim(rtrim(cast(bn.B_Brno as nvarchar(10)))) ,
ehraz.CLOS = ltrim(rtrim(cast(bn.CLOS as nvarchar(5))))
from bn_data bn
where ehraz.siba = bn.Siba
how can i do this in MS-Access 2007? this query did't works in ms access.

Does this work for you?
update ehraz
inner join bn_data bn
on ehraz.siba = bn.Siba
set
ehraz.B_CODEMELI = bn.B_CodeMelli,
ehraz.B_NAME = Trim(CStr(bn.B_Name)),
ehraz.B_FAMILY = Trim(CStr(bn.B_Family)),
ehraz.B_FATHER_N = Trim(CStr(bn.B_Father_N)),
ehraz.B_SHENAS = Trim(CStr(bn.B_Shenas)),
ehraz.B_TAVALOD = Trim(CStr(bn.B_Tavalod)),
ehraz.B_MOSHTARI = Trim(CStr(bn.B_Moshtari)),
ehraz.B_BARNO = Trim(CStr(bn.B_Brno)),
ehraz.CLOS = Trim(CStr(bn.CLOS));

this query will not work in MS-Access because some of the keywords that are used in the query are not supported by MS-Access like the cast function is not supported in MS-Access. Instead Use CStr function for type conversion into text Format and CInt function to type conversion in Number format....
try replacing these keywords and let me know if this helps.

Related

Assign widget value in spark sql statement

How do i add the value which i entered in the widget in our spark sql statement
it_flex_range = dbutils.widgets.get("it_flex_range")
iv_werks=dbutils.widgets.get("Plants")
How do i add the above value which i got from the widget in the below statement
mt_flex_1= spark.sql("select * from table name where flexcell = lit(dbutils.widgets.get("it_flex_range") and werks = lit(dbutils.widgets.get("iv_werks")")
If you are using spark-sql directly, you could follow the steps in the below link
https://docs.databricks.com/notebooks/widgets.html#using-widget-values-in-spark-sql
In case used in a python/pyspark code, you could use format() as suggested earlier or f-string...Since I do not have a table, just included them in the select statement...
dbutils.widgets.text("it_flex_range", "default_it_flex", label = "it_flex_range")
dbutils.widgets.text("Plants", "default_Plants", label = "Plants")
it_flex_range = dbutils.widgets.get("it_flex_range")
iv_werks=dbutils.widgets.get("Plants")
mt_flex_1= spark.sql(f"select '{it_flex_range}', '{iv_werks}'")
mt_flex_1.show()
+---------------+--------------+
|default_it_flex|default_Plants|
+---------------+--------------+
|default_it_flex|default_Plants|
+---------------+--------------+

Convert MS Access Update Query to SQL Query

I have an MS Access Query:
'''UPDATE MyFloridaNetDataDump INNER JOIN RepoVoipAcsNonRecurring ON
'''MyFloridaNetDataDump.service_modified = RepoVoipAcsNonRecurring.Validation
'''SET RepoVoipAcsNonRecurring.Invoice = MyFloridaNetDataDump.Invoice_modified,
'''RepoVoipAcsNonRecurring.Amount = '''Round(MyFloridaNetDataDump.billable_charge*RepoVoipAcsNonRecurring.Percentage,2),
'''RepoVoipAcsNonRecurring.Billing Cycle = MyFloridaNetDataDump.bill_cycle;
I need to convert it to SQL, which I'm using in a .net application.
I have been able to convert most of the query, but when I try to perform the multiplication I get errors depending on what I leave in. Meaning if I take the ROUND function out it doesn't like the * multiplication. If I remove the multiplication line, the query runs.
'''UPDATE MyFloridaNetDataDump
'''SET MyFloridaNetDataDump.InvoiceModified = RepoVoipAcsNonRecurring.Invoice,
'''MyFloridaNetDataDump.BillableCharge * RepoVoipAcsNonRecurring.Percentage = '''RepoVoipAcsNonRecurring.Amount,
'''MyFloridaNetDataDump.BillCycle = RepoVoipAcsNonRecurring.BillingCycle
'''FROM RepoVoipAcsNonRecurring
'''WHERE MyFloridaNetDataDump.ServiceModified = RepoVoipAcsNonRecurring.Validation
I think you inverse all of your set columns
I would suggest you to do like this
UPDATE r
SET
Invoice = m.InvoiceModified,
Amount = Round(m.billablecharge*r.Percentage,2),
[BillingCycle] = m.billCycle
FROM
MyFloridaNetDataDump m
INNER JOIN RepoVoipAcsNonRecurring r ON m.serviceModified = r.Validation

Invalid number string (7498) JDBC Request

I'm converting this progress statement into SQL.
for each usr_mstr where usr_userid matches "PRF52" exclusive-lock:
assign usr_force_change = no.
end.
This is what I currently have.
UPDATE PUB.usr_mstr SET usr_force_change = 'false' WHERE usr_userid = 'PRF52'
The error that I am receiving is '[DataDirect][OpenEdge JDBC Driver][OpenEdge] Invalid number string (7498)'.
A select statement for this field is working and returns the following.
SELECT usr_force_change FROM PUB.usr_mstr WHERE usr_userid = 'PRF52'
usr_force_change
false
The column data type was of type 'LOGICAL'. This translates to type 'BIT' in SQL. I updated the statement to the following at it worked.
UPDATE PUB.usr_mstr SET usr_force_change = '0' WHERE usr_userid = 'PRF51'
You need to choose Query type as Update Statement when submit update
Update Statement - use this for Inserts and Deletes as well

NHibernate native SQL in WHERE clause

I have a Geography column in a table in SQL Server and would like to filter rows with a specific geometry type, e.g. all records where geometry type is 'Point'
The SQL query would look like
select * from GeometryTable g where g.Geography.STGeometryType() = 'Point'
How can I create a criteria for that? The criteria is going to be used with other criterias
criteria.Add(Restrictions.Add(<Geography.STGeometryType()>, some.Value)
Thanks
Use this syntax:
var criteria = session.CreateCriteria<Geometry>();
criteria.Add
(
Expression.Sql(" {alias}.[Geography].STGeometryType() = ? "
, "Point" // a place for your parameter
, NHibernate.NHibernateUtil.String)
);
var list = criteria.List<Geometry>();

UPDATE is not allowed because the statement updates view "table_name" which participates in a join and has an INSTEAD OF UPDATE trigger

I am getting the following error while executing the following query in an Stored Procedure. Could anyone help in finding the fault?
UPDATE is not allowed because the statement updates view "sup_item" which participates in a join and has an INSTEAD OF UPDATE trigger.
UPDATE si
SET
name = mc.name,
sup_item_cat_id = mc.res_sup_item_cat_id,
xf_value = mc.xf_value,
ava_start_date = mc.ava_start_date,
ava_end_date = mc.ava_end_date,
status_code = mc.status_code,
last_mod_us_id = CASE WHEN mc.last_mod_us_id = 42 THEN #posting_us_id
ELSE mc.last_mod_us_id END,
last_mod_tsp = CURRENT_tsp
FROM sup_item AS si
JOIN merch_cat_imp_sup_item AS mc
ON mc.sup_id = si.sup_id
AND mc.res_sup_item_id = si.sup_item_id
AND mc.cat_imp_event_id = #cat_imp_event_id
AND mc.accept_flag = 'y'
WHERE si.shi_flag = 'n'
I found the reference: http://msdn.microsoft.com/en-us/library/ms177523.aspx
A view with an INSTEAD OF UPDATE trigger cannot be a target of an
UPDATE with a FROM clause.
So, I have to rewrite the UPDATE statement (it still can be in a procedure) to NOT use sup_item (which is a view), but keep the underlying table(s) as needed.
Could someone please rewrite it, if anyone knows what to do?
You can use MERGE to achieve this. Try:
MERGE INTO sup_item si
USING merch_cat_imp_sup_item AS mc
ON mc.sup_id = si.sup_id
AND mc.res_sup_item_id = si.sup_item_id
AND mc.cat_imp_event_id = #cat_imp_event_id
AND mc.accept_flag = 'y'
AND si.shi_flag = 'n'
WHEN MATCHED
THEN UPDATE
SET
name = mc.name,
sup_item_cat_id = mc.res_sup_item_cat_id,
xf_value = mc.xf_value,
ava_start_date = mc.ava_start_date,
ava_end_date = mc.ava_end_date,
status_code = mc.status_code,
last_mod_us_id = CASE WHEN mc.last_mod_us_id = 42 THEN #posting_us_id
ELSE mc.last_mod_us_id END,
last_mod_tsp = CURRENT_tsp
The issue is not within your query. As per comments on your question, the entity you are updating [sup_item], isn't actually a table, it's a view. That view has an INSTEAD OF UPDATE trigger on it.
Are you able to post the SQL for the View and for the Trigger(s)?
I would also be interested, because I have a stored procedure in a database that I have inherited which tries to do this. It won't let me create the sproc in SQL 2014, but the fact that it is there in the sproc indicates to me that an earlier version of SQL server must have allowed this.
Maybe in earlier versions your procedure operated on a table, which was later replaced by a view.
You should replace your "update from" syntax by standard ANSI syntax of update.