Can't figure out how to add current date to comment - sql

I'm having problems with my sql code, i'm trying to implement a current date to my comment but i can't figure out how + i'm having syntax errors and i don't know what to do anymore. Can someone help me with the date adding to comment?
UPDATE Osalus_projektis AS op
SET op.töötasu = op.töötasu + 100,
op.comment = CONCAT(NOW()'tõusis palk 100 eurot')
FROM Osalus_projektis
INNER JOIN Osaluse_liik AS ol
ON ol.osaluse_liik = op.osaluse_liik
WHERE ol.nimetus = 'nõustaja';

MS Access uses & for string concatenation. And it doesn't support a FROM clause. This may do what you want:
UPDATE Osalus_projektis AS op INNER JOIN
Osaluse_liik AS ol
ON ol.osaluse_liik = op.osaluse_liik
SET op.töötasu = op.töötasu + 100,
op.comment = NOW() & 'tõusis palk 100 eurot'
WHERE ol.nimetus = 'nõustaja';
If there is a problem with the JOIN -- which happens a lot in MS Access -- then you can use an EXISTS clause as well.

Related

Complex JOINS in Access SQL difficult to convert to JET OLEDB

I'm a long time follower of Stack overflow but this is my first post. I'm hoping the community can help.
I have a successful Access Query that returns the required results - Perfect!
HOWEVER, I'm trying to return the same using OLEDB connection to the database within an ASP script. This is all legacy stuff however we are allowing web access to this legacy information.
MS Access (2016) shows Query as this... (works)
SELECT [EventName] & ": " & [RoundCaption] AS RoundTitle, ChunkEntryTable.WinPos
FROM ((EventTable INNER JOIN EventRoundTable ON EventTable.EventId = EventRoundTable.EventId) INNER JOIN ((RoundHeatTable INNER JOIN ChunkTable ON RoundHeatTable.RoundHeatId = ChunkTable.RoundHeatId) INNER JOIN (EventEntryTable INNER JOIN ChunkEntryTable ON EventEntryTable.EventEntryId = ChunkEntryTable.EventEntryId) ON ChunkTable.ChunkId = ChunkEntryTable.ChunkId) ON EventRoundTable.RoundKeyId = RoundHeatTable.RoundKeyId) LEFT JOIN EventEntryMemberTable ON EventEntryTable.EventEntryId = EventEntryMemberTable.EventEntryId
WHERE (((EventEntryTable.Entry1Id)=[EntryId])) OR (((EventEntryTable.Entry2Id)=[EntryId])) OR (((EventEntryTable.Entry3Id)=[EntryId])) OR (((EventEntryMemberTable.MemberId)=[EntryId]))
ORDER BY EventTable.SortIdx, EventRoundTable.RoundId DESC , EventRoundTable.IsRepechage DESC;
Doing this in OLEDB. Connection string as follows...
<%
' FileName="Connection_ado_conn_string.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="true"
' Catalog=""
' Schema=""
Dim MM_csresultdb_STRING
MM_csresultdb_STRING = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=xyz.mde;Jet OLEDB:Database Password=xxxxxxxxx;"
%>
Connection works perfectly but I can't seem to get the SQL command to work. I get "No value given for one or more required parameters".
NOTE: I have replaced [EntryID] in 4 places with a valid value and it works perfectly in Access just not outside of Access using OLEDB. Here's what the SQL is I'm using...
SELECT EventTable.EventName & ": " & EventRoundTable.RoundCaption AS RoundTitle, ChunkEntryTable.WinPos FROM
((EventTable INNER JOIN EventRoundTable ON EventTable.EventId = EventRoundTable.EventId) INNER JOIN
((RoundHeatTable INNER JOIN ChunkTable ON RoundHeatTable.RoundHeatId = ChunkTable.RoundHeatId) INNER JOIN
(EventEntryTable INNER JOIN ChunkEntryTable ON EventEntryTable.EventEntryId = ChunkEntryTable.EventEntryId) ON ChunkTable.ChunkId = ChunkEntryTable.ChunkId) ON ChunkTable.ChunkId = ChunkEntryTable.ChunkId)
ON EventRoundTable.RoundKeyId = RoundHeatTable.RoundKeyId)
WHERE ((EventEntryTable.Entry1Id)=4741) OR ((EventEntryTable.Entry2Id)=4741) OR ((EventEntryTable.Entry3Id)=4741)
ORDER BY EventTable.SortIdx, EventRoundTable.RoundId DESC , EventRoundTable.IsRepechage DESC;
FOUND PROBLEM ** See answer below
FOUND PROBLEM ** It's to do with this part of the SQL...
[EventName] & ": " & [RoundCaption] AS RoundTitle
Changed to
[EventName], [RoundCaption] AS RoundTitle
and it works but gives me two separate fields rather than the one concatenated field called "RoundTitle". So I'll join the two result fields during the display output rather than at the query stage.
Whew! That many days to figure out. Thanks to the comments that kinda steered me in that direction of the AS part of the statement.

SQL Update statement not working - SQL Server

I am trying to run the below sql statement (SQL Server), however getting the error
"FROM clause in UPDATE and DELETE statements cannot contain subquery sources or joins."
update fp
set fp.totalcapacity = hc.totalcapacity,
fp.sellablecapacity = hc.sellablecapacity
from [fact].[FinalPosition] fp
join fact.[HotelCapacity] hc
on fp.hotelkey = hc.hotelkey
and fp.staydate = hc.staydate
where fp.staydate = '2016-06-18'
I can't seem to understand why I am getting this error. Any idea?
I think the syntax you want is:
update fp
set totalcapacity = hc.totalcapacity,
sellablecapacity = hc.sellablecapacity
from fp join
fact.[HotelCapacity] hc
on fp.hotelkey = hc.hotelkey and fp.staydate = hc.staydate
where fp.staydate = '2016-06-18';
If you want fp to refer to an actual table, include that in the from clause and make the fp the alias for the table.

SQL Statement won't work anymore after small change. VBA

this Statement works totaly fine in ORACLE SQL DEVELOPER, but when I insert it to my vba makro it won't return me my BLOB files from the database. The statement worked before in VBA with a data-number variable instead of referencing to SYSDATE...
Provider is OraOLEDB.Oracle, the Connections string "works/opens" but there is no data to pass my - IF rs.EOF = FALSE Then - I've already tested eof=true but no data comes through....Any ideas ? thx!
select datas
from tdb
INNER JOIN (select datas_id
from tfdz
INNER JOIN (select fb_id
from tfb
INNER JOIN (select pu_id
from tpu
INNER JOIN (select tap.p_id
from tap
INNER JOIN (SELECT po_id
FROM tpo
WHERE tpo.lastdate like (SYSDATE-1)
) sub_tpo
ON tap.po_id = sub_tpo.po_id and tap.lastdate like (SYSDATE-1)
) sub_tap
ON tpu.p_id = sub_tap.p_id
) sub_tpu
ON tfb.pu_id = sub_tpu.pu_id
where tfb.deleated = 0
) sub_tfb
ON tfdz.fb_id = sub_tfb.fb_id
) sub_tfdz
ON tdb.datas_id = sub_tfdz.datas_id
order by sub_tfdz.datas_id asc
It would be good to see how you are passing it, I assume as a string, have you tried.
WHERE tpo.lastdate like (" & Format(DateAdd("d", -1, Now()), "DD/MMM/YYYY") & ")"
You may need to change the format to be compatible Oracle date processing

I get an error 3075 (Missing operator) when trying to run an sql. update query

The VBA code is:
''sql1 = "select InvoiceCNotes.[docsetamount] ,InvoiceCNotes.[docsetamount] + AllocationsTEMP.[paidamount] from AllocationsTEMP inner join InvoiceCNotes on AllocationsTEMP.Docnumber = InvoiceCNotes.Docnumber where InvoiceCNotes.[docnumber] = AllocationsTEMP.[docnumber] AND AllocationsTEMP.[paidamount] <> 0"
sqlline = sql1
DoCmd.RunSQL sql1
The code as displayed in sqlline above, is as follows:
Update InvoiceCNotes
set InvoiceCNotes.[docsetamount] = InvoiceCNotes.[docsetamount] + AllocationsTEMP.[paidamount]
from AllocationsTEMP inner join InvoiceCNotes
on AllocationsTEMP.Docnumber = InvoiceCNotes.Docnumber
where InvoiceCNotes.[docnumber] = AllocationsTEMP.[docnumber]
AND AllocationsTEMP.[paidamount] <> 0
I have looked at other questions here regarding the same error, but still I am missing something.
From previous questions, I added the table names, and bracketed the field names.
I checked the table specs to see that docsetamount and paidamount are both defined as [NUMBER,double,fixed,2], the two docnumbers are both long integers, and paidamount is also NUMBER,double,fixed,2
Now I am possibly staring into the problem and not noticing my error, as I have developed quite a few apps in Access over the past five years (since retirement I should add) so I must have done something wrong.
Do you notice the mistake?
The UPDATE t1 SET t1.f=foo FROM t1 JOIN t2 syntax with the FROM is from Sql Server.
In Access SQL you put the JOIN in the first clause, like this:
UPDATE InvoiceCNotes INNER JOIN AllocationsTEMP
ON InvoiceCNotes.Docnumber = AllocationsTEMP.Docnumber
SET InvoiceCNotes.[docsetamount] = InvoiceCNotes.[docsetamount] + AllocationsTEMP.[paidamount]
WHERE AllocationsTEMP.[paidamount] <> 0
where InvoiceCNotes.[docnumber] = AllocationsTEMP.[docnumber] is superfluous because it's already in the JOIN condition.
I found a totally different syntax - and it works just fine.
Maybe my original source was wrong, as I did exactly hat it said.
My new syntax for the update is:
UPDATE InvoiceCNotes INNER JOIN AllocationsTEMP
ON InvoiceCNotes.Docnumber = AllocationsTEMP.Docnumber
SET InvoiceCNotes.docsetamount = InvoiceCNotes.[docsetamount]+AllocationsTEMP.[paidamount]
WHERE (((InvoiceCNotes.docnumber)=[AllocationsTEMP].[docnumber])
AND ((AllocationsTEMP.paidamount)<>False))
Maybe this question should just be removed - it will cause confusion rather than to be helpful. I can't do that, or I would.
Apologies to whoever might have tried to help - and thanks for the effort.
This is now SOLVED

date time in combobox

i am using visual stdio 2008 and sql server 2005
dim selectquery = "SELECT Purchase_master.Customer_name, Purchase_details.Item_code, Item_Master.Name,
Purchase_details.Quantity, Purchase_details.Cost, Purchase_master.Date
FROM Item_Master INNER JOIN (Purchase_master INNER JOIN Purchase_details ON
Purchase_master.Bill_id = Purchase_details.Bill_id) ON Item_Master.Item_code = Purchase_details.Item_code
WHERE Purchase_master.Date= " + cboPDate.SelectedValue.ToString()
when this selectquery executed it gives me
error
"ERROR near syntax 12"
my cboPDate is a combobox binded with my database which return's data and time in
"2/18/2011 12:00:00 AM"
please help me out
You need to add quotes around your date.
Try
dim selectquery = "SELECT Purchase_master.Customer_name, Purchase_details.Item_code, Item_Master.Name,
Purchase_details.Quantity, Purchase_details.Cost, Purchase_master.Date
FROM Item_Master INNER JOIN (Purchase_master INNER JOIN Purchase_details ON
Purchase_master.Bill_id = Purchase_details.Bill_id) ON Item_Master.Item_code = Purchase_details.Item_code
WHERE Purchase_master.Date= '" + cboPDate.SelectedValue.ToString() +"'"
Better yet, use SQL parameters.
I suspect it is treating it as a delimiter.It would be better to change it to
WHERE Purchase_master.Date=#Your_date
And then add the date as a parameter, this would prevent SQL injection attacks and also promote plan caching
Try this:
dim selectquery = string.Format("SELECT Purchase_master.Customer_name, Purchase_details.Item_code, Item_Master.Name,
Purchase_details.Quantity, Purchase_details.Cost, Purchase_master.Date
FROM Item_Master INNER JOIN (Purchase_master INNER JOIN Purchase_details ON
Purchase_master.Bill_id = Purchase_details.Bill_id) ON Item_Master.Item_code = Purchase_details.Item_code
WHERE Purchase_master.Date= '{0}'", cboPDate.SelectedValue.ToString());
you have to add quots to the value. :)