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
Related
I am applying a mask to data and believe the best way is to use a Case Statement. However, I need the case statement to run a sub query. When I pull data, it will either be a number or appear as 99999999999v999b:99999999999v999-
Using
TO_NUMBER(REGEXP_REPLACE(RD.subm_quantity, '^(\d+)(-)?$', '\2\1'))/1000 as "Submitted_Quantity"
This will convert it to a number. So if 00000000100000 is present, it will convert to 100
However, I need a case to not divide when not needed. To determine if I need to divide, I need to add a rule in the below sql:
if the result is 99999999999v999b:99999999999v999-, apply the conversion;
if not, just output RD.subm_quantity.
How can I get a case statement to run a query?
Running in TOAD for Oracle:
select m.mask
FROM Valiuser.ivd_mapping m,
Valiuser.ivd_mappingset s,
Valiuser.ivd_mapping_record r,
Valiuser.ivd_transaction_file tf,
VALIUSER.ivd_transaction_record_details RD
WHERE s.mappingset_id = r.mappingset_id
AND r.mapping_record_id = m.mapping_record_ID
AND m.repository_column_id = '34'
AND s.mappingset_id = tf.MAPPINGSET_ID
AND rd.file_id = tf.file_id
AND rd.TRANSACTION_RECORD_ID =
If the mask and original subm_quantity are both available from the query you showed, which seems to be the same as that includes the rd table you're referencing in the conversion, then I think you want something like this:
case when m.mask = '99999999999v999b:99999999999v999-'
then TO_NUMBER(REGEXP_REPLACE(rd.subm_quantity, '^(\d+)(-)?$', '\2\1')) / 1000
else rd.subm_quantity
end as "Submitted_Quantity"
rather than a subquery. So plugged into your current query that would make it:
SELECT
case when m.mask = '99999999999v999b:99999999999v999-'
then TO_NUMBER(REGEXP_REPLACE(rd.subm_quantity, '^(\d+)(-)?$', '\2\1')) / 1000
else rd.subm_quantity
end as "Submitted_Quantity"
FROM
Valiuser.ivd_mapping m,
Valiuser.ivd_mappingset s,
Valiuser.ivd_mapping_record r,
Valiuser.ivd_transaction_file tf,
Valiuser.ivd_transaction_record_details rd
WHERE
s.mappingset_id = r.mappingset_id
AND r.mapping_record_id = m.mapping_record_ID
AND m.repository_column_id = '34'
AND s.mappingset_id = tf.mappingset_id
AND rd.file_id = tf.file_id
AND rd.Transaction_Record_Id = <?>
or with modern join syntax instead of the old version, something like:
SELECT
case when m.mask = '99999999999v999b:99999999999v999-'
then TO_NUMBER(REGEXP_REPLACE(rd.subm_quantity, '^(\d+)(-)?$', '\2\1')) / 1000
else rd.subm_quantity
end as "Submitted_Quantity"
FROM Valiuser.ivd_mapping m
JOIN Valiuser.ivd_mapping_record r ON r.mapping_record_id = m.mapping_record_ID
JOIN Valiuser.ivd_mappingset s ON s.mappingset_id = r.mappingset_id
JOIN Valiuser.ivd_transaction_file tf ON tf.mappingset_id = s.mappingset_id
JOIN Valiuser.ivd_transaction_record_details rd ON rd.file_id = tf.file_id
WHERE m.repository_column_id = '34'
AND rd.transaction_record_id = <?>
How to Convert this sql query to Linq.
select sum(OutstandingAmt)from IvfReceiptDetails where IvfReceiptId IN(select IvfReceiptId from IvfReceipts where PatientId = 'SI-49650')
I think it is easier to translate SQL using query comprehension syntax instead of lambda syntax.
General rules:
Translate inner queries into separate query variables
Translate SQL phrases in LINQ phrase order
Use table aliases as range variables, or if none, create range variables from table names
Translate IN to Contains
Translate SQL functions such as DISTINCT or SUM into function calls on the entire query.
Here is the code:
var IvfReceiptIds = from IvfReceipt in IvfReceipts
where IvfReceipt.PatientId = "SI-49650"
select IvfReceipt.IvfReceiptId;
var OutstandingAmtSum = (from IvfReceiptDetail in IvfReceiptDetails
where IvfReciptIds.Contains(IvfReceiptDetail.IvfReceiptId)
select IvfReceiptDetail.OutstandingAmt).Sum();
Try this, First get all IvfReceiptId in array based on your inner query used in where condition then check contains. Change name of your _context if it's different.
var arrIvfReceiptId = _context.IvfReceiptDetails.Where(p=>p.PatientId == "SI-49650").ToArray();
var sum = (from ird in _context.IvfReceiptDetails.Where(p=> arrIvfReceiptId.Contains(p.IvfReceiptId))
select OutstandingAmt).Sum();
I have a query that is working in sql management studio, but when I run this is SSRS/Visual Studio I get the error "cannot read the next data row for the dataset dataset1. Error converting data type nvarchar to numeric"
select
concat(
right(replace(oe_hdr.po_no, '-', ''),8),
right(concat('000',job_price_line.line_no),3),
format(oe_pick_ticket_detail.unit_quantity, '00000000'),
cast(job_price_line.customer_part_no as char(20)),
oe_pick_ticket.invoice_no) as [po/line/release/qty/cust part no as 20 characters / invoice]
from oe_pick_ticket
join oe_pick_ticket_detail on oe_pick_ticket_detail.pick_ticket_no = oe_pick_ticket.pick_ticket_no
join oe_hdr on oe_hdr.order_no = oe_pick_ticket.order_no
join job_price_hdr on oe_hdr.job_price_hdr_uid = job_price_hdr.job_price_hdr_uid
join job_price_line on job_price_line.inv_mast_uid = oe_pick_ticket_detail.inv_mast_uid and job_price_line.job_price_hdr_uid = oe_hdr.job_price_hdr_uid
join ship_to on ship_to.ship_to_id = oe_hdr.address_id
join branch on branch.branch_id = ship_to.default_branch
join customer on customer.customer_id = oe_hdr.customer_id
where oe_pick_ticket.invoice_no in ('1218972', '1218983')
and job_price_line.row_status_flag != '705'
and oe_pick_ticket_detail.ship_quantity > '0'
But when I run this for SSRS - and I add more parameters to my where clause like this:
where oe_pick_ticket.invoice_no in (#invoiceno1, #invoiceno2, #invoiceno3,
#invoiceno4, #invoiceno5, #invoiceno6, #invoiceno7 ,#invoiceno8,
#invoiceno9, #invoiceno10, #invoiceno11, #invoiceno12, #invoiceno13,
#invoiceno14, #invoiceno15, #invoiceno16, #invoiceno17, #invoiceno18,
#invoiceno19, #invoiceno20)
and job_price_line.row_status_flag != '705'
and oe_pick_ticket_detail.ship_quantity > '0'
It returns the error
I found out that I had to allow null expressions on all of my parameters. This solved my problem.
I had a similar problem. I changed TIMING in Data source from 30 to 100. This solved my problem. My theory is that my Dataset was too big.
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.
Been trying to get the following query working for a few hours now and am running out of ideas. Can anyone spot where I'm going wrong. Any pointers much appreciated.
CalEvents = (List<CalEvent>)session.CreateSQLQuery(#"
SELECT *
FROM dbo.tb_calendar_calEvents
INNER JOIN dbo.tb_calEvents
ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id)
WHERE dbo.tb_calendar_calEvents.calendarID = 'theCalID'"
)
.AddEntity(typeof(CalEvent))
.SetInt64("theCalID", cal.id);
Error:
Kanpeki.NUnit.CalUserTest.Should_return_logged_in_user:
System.ArgumentException : Parameter theCalID does not exist as a
named parameter in [SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN
dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID =
dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID =
'theCalID']
"SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID = 'theCalID'"
should be
"SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID = :theCalID"
= 'theCalID' should be written as = :theCalId; :theCalId is how you use named parameters even in Native SQL Queries.
You should remove the query.ExecuteUpdate() call.
Doing the query.List() is enough to issue the query on the session and return the result set.