Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Regenerate sno
Message
From
13/07/2017 15:23:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
13/07/2017 03:50:57
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01652643
Message ID:
01652648
Views:
48
>Dear Experts
>
>Sir, I am SQLSERVER 2008 R2.
>Table has smalldatetime column and data looks like image1
>
>
>
>In original table, I want to regenerate sno column on date+party index like image2
>(sorted on date+party)
>
>
>
>Please help


sno is persistent or imaginary? If so you would need to an update query else a simple select would do.

sno doesn't exist as a column and generate on the fly:
   select [date], row_number() over (partition by cast([date] as date) order by cast([date] as date), party) as sno, party
   from myTable
   order by cast([date] as date), party
sno exists, update and return with updated values:
with mySort (date, sno, party) as 
(
   select [date], row_number() over (partition by cast([date] as date) order by cast([date] as date), party) as sno, party
   from myTable
)
update myTable
set sno = mySort.sno
from mySort 
where mySort.date = myTable.date and mySort.party = myTable.party;

select [date], sno, party
   from myTable
  order by cast([date] as date), sno
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform