Reputation: 13
The problem is in the title, I'd like to update a field with GETDATE()
to get the current time when the query is executed but it returns a null value. I previously saw that the column must not be nullable
and the column default must be 'NULL
' in order to work, which is the case.
The column where I want the GETDATE()
is 'dt_saisie'
Here is my query :
BEGIN
UPDATE [proliv_min].[dbo].[proliv_production]
SET
dt_saisie = GETDATE(),
dcf = null,
login = 'user',
commentaire = '[TEST] Update'
WHERE
id_kopf = (
SELECT
id
FROM
[proliv_min].[dbo].[proliv_kopf]
WHERE
1=1
AND cprj = '962753'
AND statut IS NULL
);
END
Thanks for any help
Pierre
Upvotes: 1
Views: 2246
Reputation: 832
You can run the following query to update your data. I have changed to add in
in where condition. Because if you do not get data in select
statement, no update will happen in your table.
BEGIN
UPDATE [proliv_min].[dbo].[proliv_production]
SET
dt_saisie = GETDATE(),
dcf = null,
login = 'user',
commentaire = '[TEST] Update'
WHERE
id_kopf in (
SELECT
id
FROM
[proliv_min].[dbo].[proliv_kopf]
WHERE
1=1
AND cprj = '962753'
AND statut IS NULL
);
END
Upvotes: 2