Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Seconds()
Message
From
10/02/2019 10:08:26
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01666213
Message ID:
01666216
Views:
57
>Thanks sir for helping
>
>But
>
>These codes will not update nSeconds column in SQLserver table.
>
>I need for sqlserver, please

For SQL you would need a strictly incremental key, or else you wouldn't be able to say what is the previous record - there is no "previous record" there, as the physical order of records is not guaranteed by anything. You wouldn't even be able to write updates without a key, bescause there's no "current record" either. Instead, each update statement needs a where clause.

Also, instead of VFP trick of using the same cursor twice, in SQL you would have to use a self-join in the update statement, which is where it gets complicated and, believe it or not, I haven't done it.

Perhaps an easier way would be to
declare @dmx, @dnow datetime;
select @dmx=max(date) from junk
select @dnow=getdate()
insert into junk (date, nseconds) values (@dnow, datediff(seconds, @dnow, @dmx)
IOW, don't write values without seconds and fill them in later - calculate them from the max datetime before inserting. If it's not the current datetime that you're inserting, then it's a different matter - this would be a stored procedure where you'd pass @dnow as a parameter, and the 2nd line would be
select @dmx=max(date) from junk where date<@dnow

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform