Hi guys,
I want to copy data between two copies of the same object (create replica of the table) using SQL statement.
Something like:
insert into [Test Table 02] select * from [Test Table 01]
It gives an error:
Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.
As suggested by the error message I can change this code into
insert into [Test Table 02] (field1, field2,...,field100) select field1, field2,...,field100 from [Test Table 01]
or
insert into [Test Table 02] select DEFAULT,field1, field2,...,field100 from [Test Table 01]
But I don't like those... I need a solution without listing the columns.
According to help, for example, when you use TRANSFERFIELDS(..., FALSE) in NAV - timestamp value will not change. How they achieve this?
Is there any setting which forces SQL to accept value in timestamp field?
Thanks
Answers
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Just preparing SQL_statement in NAV code and then execute it as
ADO.Execute(SQL_Statement)
But the trick is ADO.execute is failing when statement length is more than 2,000 characters - and there are tables where single column listing (you need to list them twice per statement) is longer than 5,000 characters.... so it happens sometimes that whole statement is about 12,000 characters...
That's why I need solution without column names - a generic one.
So the best (but slower) way is using recordref.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I got for example:
As you can see by using temporary table I managed to reduce statement to require only one column listing (as for second I can now use SELECT *).
But first column listing (column1,column2,..,column100) is still required - I need something clever to remove it as well...
:-k
I belive a "SELECT * INTO x2 FROM x1..." will keep timestamps in TSQL if the x2 table does not exist. It will be auto created with same table structure as x1.
Another possible way (not testet) is to change the datatype of the timestamp row in x2 to binary(8) which should be what a timestamp is stored in anyway.
But I have no clue how NAV will react to such a table and you will probably get into problems if you modify rows later (the binary(8) will not be updated).
Regards
Gert Lynge
Inside of the SP you can build the sql statement in a varchar(max) variable and run it with exec or sp_executesql.
So the length of your statement doesn't matter.
You can call the SP from NAV via ADO.
I've also seen solutions inside NAV using 'Microsoft Script Control 1.0'.ScriptControl-Automation.
You can build a vbscript using ADO in an instance of the ScriptControl variable.
With the function ScriptControl.AddCode you can add as many code as you need.
I prefer the stored proc.
regards
ndbcs
Remember that database updates made by external calls are not under NAV's transaction control. That means if a NAV error occurs after you have run your external code, the changes made by NAV code are rolled back, but not those by the external code. This can leave your DB in an unexpected condition. That's not to say direct SQL can't be useful.
Table created this way is losing some part of its structure and NAV is no longer liking it - but maybe we can do something about this...
SQL does not like this idea:
Cannot alter column 'timestamp' because it is 'timestamp'.
Yes... probably it is the safest option. I would prefer to use NAV code but this could be acceptable compromise...
Maybe I will play with this idea sometime... but I also prefer stored proc
Yes It is a migration exercise - not a solution for daily operations/transactions. I am not worried about transaction control here.
Thanks everyone!
http://blog.sqlauthority.com/2008/02/06 ... ql-server/
you don't need to specify the fields
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
It's true and i hope that MS will create interface to current sql connection in future versions. Now I have to use this trick to make changes by SQL in same transaction as a Nav.
Nav, T-SQL.