Getting error while executing the query? - sql

When I run my query:
UPDATE oms.Document_Latest
SET size ='54324', CheckInBy = 'Anshul123',
Status ='checkedin', CheckOutBy = 'NULL',
CheckInOn = '4/28/2016 1:45:36 PM', CheckOutOn = 'NULL'
WHERE (Id = '1')
Datatype of columns are given in image which is attached with this question
I get this error:
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
Please help me find the reason why I get this error while execute this query.
Thanks

You receive an error that because you trying to update CheckOutOn column of datatype DATETIME with string 'NULL'. You have to remove quotes '' from NULL in following:
UPDATE oms.Document_Latest
SET size ='54324',
CheckInBy = 'Anshul123',
Status ='checkedin',
CheckOutBy = NULL,
CheckInOn = '4/28/2016 1:45:36 PM',
CheckOutOn = NULL
WHERE (Id = '1')

Related

Update multiple columns from a sub query

UPDATE PINPOINT_SUPPLEMENT
SET (ATTACHMENT_VALUE,ATTACHMENT_TYPE) = (
SELECT key,'file'
FROM PINPOINT_DOCUMENT
WHERE PINPOINT_SUPPLEMENT.ATTACHMENT_VALUE::integer = PINPOINT_DOCUMENT.DOCUMENT_ID
)
WHERE ATTACHMENT_VALUE IS NULL
Getting Error when i execute this query
ERROR: syntax error at or near "SELECT"
LINE 3: SELECT key,'file
update PINPOINT_SUPPLEMENT
set
ATTACHMENT_VALUE = PINPOINT_DOCUMENT.key,
ATTACHMENT_TYPE = 'file'
from PINPOINT_DOCUMENT
where
PINPOINT_SUPPLEMENT.ATTACHMENT_VALUE::integer = PINPOINT_DOCUMENT.DOCUMENT_ID
and PINPOINT_SUPPLEMENT.ATTACHMENT_VALUE IS NULL
or
update PINPOINT_SUPPLEMENT
set
(ATTACHMENT_VALUE,ATTACHMENT_TYPE) = (PINPOINT_DOCUMENT.key, 'file')
from PINPOINT_DOCUMENT
where
PINPOINT_SUPPLEMENT.ATTACHMENT_VALUE::integer = PINPOINT_DOCUMENT.DOCUMENT_ID
and PINPOINT_SUPPLEMENT.ATTACHMENT_VALUE IS NULL
Support for updating tuples was introduced in Postgres 9.5, so you can't use that syntax with your version.
But as the second value is a constant I don't see a reason to use that syntax to begin with:
UPDATE PINPOINT_SUPPLEMENT
SET ATTACHMENT_VALUE = (SELECT "key"
FROM PINPOINT_DOCUMENT
WHERE PINPOINT_SUPPLEMENT.ATTACHMENT_VALUE::integer = PINPOINT_DOCUMENT.DOCUMENT_ID),
ATTACHMENT_TYPE = 'file'
WHERE ATTACHMENT_VALUE IS NULL
Note, that the sub-query might result in an error if there is more than one ATTACHMENT_VALUE for a document_id!

How to solve the error_syntax error near '< '

Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '<'.
I got the above error message every time I tried to execute the below query.
UPDATE [dbo].[FM1]
SET [Datum] = <Datum, smalldatetime,>
,[Gesamtzeit] = <Gesamtzeit, nvarchar(5),>
You can try this no need to specify datatype here.
UPDATE [dbo].[FM1]
SET [Datum] = 'YourValue'
,[Gesamtzeit] = 'YourValue'
where ...

Msg 8114, Level 16, State 5, Line 2 Error converting data type nvarchar to bigint

I'm trying to select the following and gets an error for
converting data type nvarchar to bigint.
SELECT distinct NonReportingPartyLEI, NonReportingPartyCountry
FROM [AVA_DWH].[dbo].[Dynamic_Data]
where NonReportingPartyLEI in (5116854,
5124879,
5111791,
5126782,
5118409,
5120091,
5121994,
5113143,
5122326)
Columns data types:
NonReportingPartyLEI (bigint, null)
NonReportingPartyCountry (nvarchar(200), null)
Please help
Thanks!

Edit column data at SQL

I am trying to update my retrieved data as described below:
UPDATE vw_public_task_priority
SET task_state = REPLACE(task_state, 'NULL', 'DONE')
After I execute it I get the next error:
Msg 4406, Level 16, State 1, Line 41
Update or insert of view or function 'vw_public_task_priority'
failed because it contains a derived or constant field.
Can you please advice to me what I'm doing wrong + there is a possibility to update the results at new column instead of edit "task_state" data?
Thanks!
Try this
UPDATE vw_public_task_priority SET task_state = 'DONE' where task_state is null

Updating multiple columns in Oracle

If I try to add in (, CCY_TO_BASE_RATE = EXCHANGERATE.MID_RATE) into the update statement it shows the following errors.
ORA-06550: line 8, column 21:
PL/SQL: ORA-00923: FROM keyword not found where expected
ORA-06550: line 6, column 1:
PL/SQL: SQL Statement ignored
However, without that (, CCY_TO_BASE_RATE = EXCHANGERATE.MID_RATE), the statement is valid.
So how would I need to edit my codes so that the statement will be valid?
DECLARE
v_system_base_ccy NVARCHAR2(10);
BEGIN
v_system_base_ccy := dbo.Fn_parameter('SYSTEMBASECCY');
UPDATE tbl_dvcollateral A
SET coll_value_base = (SELECT coll_value * Nvl(EXCHANGERATE.mid_rate, 1),
ccy_to_base_rate = EXCHANGERATE.mid_rate
FROM (SELECT mid_rate,
from_ccy
FROM TABLE(
dbo.Fn_exchangeratetable(:V_AS_OF_DATE,
NULL,
v_system_base_ccy) )
)EXCHANGERATE
WHERE A.ccy = EXCHANGERATE.from_ccy(+)),
last_updated_by = :V_LOGIN_ID,
last_updated_datetime = To_timestamp(To_char(systimestamp,
'YYYY-MM-DD HH24:MI:SS'),
'YYYY-MM-DD HH24:MI:SS')
WHERE as_of_date = :V_AS_OF_DATE
AND record_status_id = :V_AUTHORIZED;
END;
I may be misinterpreting what you're doing, but you seem to have the target column on the wrong side of the update statement:
UPDATE tbl_dvcollateral A
SET (coll_value_base, ccy_to_base_rate) =
(SELECT coll_value * Nvl(EXCHANGERATE.mid_rate, 1),
EXCHANGERATE.mid_rate
FROM (SELECT mid_rate,
...
In line 8 you have
ccy_to_base_rate = EXCHANGERATE.mid_rate
as a select-expression. This is technically a boolean which Oracle SQL does not tolerate.
You need to remove this expression. I cannot tell what you need to replace it with since I have no idea what you tried to formulate.