0

I am having an issue putting the below SQL query into Python :

insert into GERVERSION values (10, 'xxxxxxxx', 7, 4, 2, getdate(),'')

Note that in SQL , I have timestamp for the getdate() part

Can anyone please help me out with the right syntax to put this into work ?

Ilyes
  • 14,640
  • 4
  • 29
  • 55
  • 1
    Do you **really** have a column with datatype `TIMESTAMP` in SQL Server? That is **not** a column to hold date and time information in SQL Server; It's been renamed `ROWVERSION` because it really is a system-internal, binary version number of the row - it has nothing to do with date and time. Use `DATETIME2(n)` for handling date and time instead – marc_s Apr 10 '20 at 08:49
  • Please post the DDL (`CREATE TABLE ...`) – Ilyes Apr 10 '20 at 08:55
  • getdate() it will give timestamp value. pls check you are inserting into correct column – B.Muthamizhselvi Apr 10 '20 at 09:13
  • Also: **what** issue do you have? Do you get an error message - if so, **what** error? – marc_s Apr 10 '20 at 10:43
  • ... @marc_s, although the documentation states that `timestamp is the synonym for the rowversion data type`, it is the other way around, rowversion is a synonym for timestamp.The data type remains timestamp: `create table a(col rowversion);exec sp_help 'a';drop table a;` ... `select type_id('rowversion'), type_id('timestamp')` – lptr Apr 10 '20 at 11:00

1 Answers1

0

Try using INSERT INTO ... SELECT syntax:

INSERT INTO GERVERSION
SELECT 10, 'xxxxxxxx', 7, 4, 2, GETDATE(), '';
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Tim - just out of curiosity - what's the benefit in your opinion to use the `INSERT INTO.. SELECT` approach over the `INSERT INTO .... VALUES ` one? Since the inserted values are all constants, variables or results of function calls like `GETDATE()`, I don't really see any advantage to this approach - am I missing something? – marc_s Apr 10 '20 at 10:42
  • @marc_s Honestly I didn't even know that it were possible to have function calls inside a `VALUES` clause. In some databases, it isn't allowed. – Tim Biegeleisen Apr 10 '20 at 10:44
  • OK - I see your point - but yes, in SQL Server, calling a built-in function like `GETDATE()` (or preferably `SYSDATETIME()` these days) is in fact possible inside a `VALUES()` clause – marc_s Apr 10 '20 at 10:47
  • @marc_s, correct . Using getdate() worked solved it . Thank you – sameh grami Apr 10 '20 at 12:29