My question is very simple:
I have a column named "DateProcessed". Whenever User Clicks a Button, the column should be updated for each row with the current System.Date.
Here is my code:
update dbo.JobStatus SET DateShipTransmitProcessed = ???? WHERE JobTableId = #JobTableId
What should go in ????. Thanks for your help!
The ANSI standard would be to use current_timestamp, which should work for MySql, SQL Server, and any other ANSI compliant RDBMS.
update dbo.JobStatus SET DateShipTransmitProcessed = current_timestamp WHERE JobTableId = #JobTableId
If you are on SQL server..
update dbo.JobStatus SET DateShipTransmitProcessed = GetDate() WHERE JobTableId = #JobTableId
Related
A similar question was asked.
The goal is to create the function described here:
def DB_Query(d1, d2):
conn = pyodbc.connect('DSN=DATASOURCE')
tbl = "SELECT TableA.Field_1 \
FROM TableA \
WHERE TableA.Date>=? AND TableA.Date<=?"
df_tbl= pd.read_sql_query(tbl, conn, params = (d1,d2))
conn.close
return df_tbl
This worked on database with SQL Server driver, but it won't work on Microsoft ODBC for Oracle driver.
When I give, for e.g., d1 = '2020-02-20' and d2 = '2020-02-25', I get error
('HY004', '[HY004] [Microsoft][ODBC Driver Manager] SQL data type out of range (0) (SQLBindParameter)')
I understand in Oracle, you need DATE 'YYYY-MM-DD' to express a date, which is different from SQL server where you can just use 'YYYY-MM-DD'.
I've tried add DATE in front of ? but doesn't work. Any ideas?
Found solution here. Just define d1 as date(2020,02,20).
How to parameterize datestamp in pyODBC query?
update qtable set Section = Section + ',Teaching' where qid=522
this update statement doesnot concat/append the values.
Section contains null value initially.
Use concat() if you are working with SQL Server 2012 instead:
update qtable
set Section = concat(Section, ',Teaching')
where qid=522;
For older version you can use
update qtable
set Section = coalesce(Section, '') + ',Teaching'
where qid=522;
Please try
update qtable set Section = CONVERT(VARCHAR(255),ISNULL(Section,'')) + ',Teaching' where qid=522
I'm attempting to execute this SQL Update statement and it's not working. Does anyone know why ?
update dbo.EBSTable
set CommandField = replace(CommandField, '%APPL.mbm_aging_file', '%APPL.mbm_aging_file)')
where Command like '[%]APPL.mbm_aging_file'
Basically, I'm just trying to add a ")" to the end of the data appearing in the CommandField field where the value is %APPL.mbm_aging_file (The "%" actually appears in the data).
I discovered my where clause was inadequate (like me with SQL). It should read
update dbo.EBSTable set CommandField = replace(CommandField, '%APPL.mbm_aging_file', '%APPL.mbm_aging_file)') where Command like '%[%]APPL.mbm_aging_file%'
That statement worked.
update dbo.EBSTable
set CommandField = '%APPL.mbm_aging_file' + ')' -- or set CommandField = '%APPL.mbm_aging_file)'
where Command = '%APPL.mbm_aging_file'
You can do this, as you only need to add ) at the end only for this specific case.
We recently switched from Oracle to SQL Server and we had this old update statement that used to work but is now giving the error 'operation must be an updateable query'. Well the query type is set to Update, I have tried running it as administrator with no success and we are able to run select statements with no problem, so the connection must be ok?
I'm not sure if I'm just missing something really simple as I'm used to working in SSMS and not Access. The code for the Update statement is below:
UPDATE dbo_LEARNER_AIMS
INNER JOIN dbo_REGISTRATION_UNITS ON dbo_LEARNER_AIMS.RUL_CODE = dbo_REGISTRATION_UNITS.RUL_CODE
SET dbo_LEARNER_AIMS.END_DATE = [EXP_END_DATE],
dbo_LEARNER_AIMS.COMPLETION = "10",
dbo_LEARNER_AIMS.OUTCOME = "40",
dbo_REGISTRATION_UNITS.FES_PROGRESS_CODE = "EXT",
dbo_REGISTRATION_UNITS.FES_PROGRESS_DATE = [EXP_END_DATE],
dbo_REGISTRATION_UNITS.PROGRESS_STATUS = "X"
WHERE (((dbo_LEARNER_AIMS.END_DATE) Is Null)
AND ((dbo_LEARNER_AIMS.FUNDING_YEAR)="17")
AND ((dbo_LEARNER_AIMS.LEARNING_AIM) = [Enter Aim])
AND ((dbo_LEARNER_AIMS.EXP_END_DATE) Between #8/1/2012#
AND [enter expected end date]));
Thanks in advance to any answers.
the error 'operation must be an updateable query'.
almost always means an Indexing problem, usually a missing primary key.
also
check the properties page of the Query, look for the Snapshot vs Dynaset setting.
Try this query :
UPDATE dbo_LEARNER_AIMS
SET END_DATE = [EXP_END_DATE],
COMPLETION = "10",
OUTCOME = "40",
/*
dbo_REGISTRATION_UNITS.FES_PROGRESS_CODE = "EXT",
dbo_REGISTRATION_UNITS.FES_PROGRESS_DATE = [EXP_END_DATE],
dbo_REGISTRATION_UNITS.PROGRESS_STATUS = "X"
You can't update multiple table in one update statement ! */
FROM dbo_LEARNER_AIMS /* add this line */
INNER JOIN dbo_REGISTRATION_UNITS ON dbo_LEARNER_AIMS.RUL_CODE = dbo_REGISTRATION_UNITS.RUL_CODE
WHERE (((dbo_LEARNER_AIMS.END_DATE) Is Null)
AND ((dbo_LEARNER_AIMS.FUNDING_YEAR)="17")
AND ((dbo_LEARNER_AIMS.LEARNING_AIM) = [Enter Aim])
AND ((dbo_LEARNER_AIMS.EXP_END_DATE) Between #8/1/2012#
AND [enter expected end date]));
I need to have a query which list all the user according to the date value in the database. Problems is this, in the database the date format is 5/5/2009 4:30:12 but I want to compare with 5/5/2009. I think the value of the based date is 5/5/2009 12:00:00 and that's why I couldn't query it.
The query is something like
dim db = new databcontext
dim user = from u in db.datacontext where u.signUpTime = 5/5/2009 select u.
May someone please check this problem.
Thanks in advance.
Your theory is correct. You should either use a range in your where clause:
u.SignupTime >= new DateTime(2009,5,5,0,0,0) AndAlso _
u.SignupTime < new DateTime(2009,5,6,0,0,0)
or check only the date:
u.SignupTime.Date = new DateTime(2009,5,5)