Oct 5, 2019 11:51
Great @McNets that's awesome. Thank you so much for your time & effort.
Oct 5, 2019 11:33
Until now, I can't came up with a solution. Thanks for pointing, I'll work more to learn more.
Oct 5, 2019 11:31
@McNets Nope, that won't reset the Seq, see the expected results ^
Oct 5, 2019 11:28
Thanks for you both @PaulWhite & @McNets
Oct 5, 2019 11:25
It seems there is no solution, even if we add an identity column to the T table
Oct 5, 2019 11:21
Thnx @PaulWhite
Oct 5, 2019 11:21
@McNets As you can see there is no order there and there is no column to determine the order
Oct 5, 2019 11:19
@PaulWhite There is no reason, expect I believe I'll get answers here too (quick one) and it's just for learning, no matter if I got answers or not
Oct 5, 2019 11:18
@McNets Nope, It's a seq, if val = 2 then 0, else start the seq again from 1
Oct 5, 2019 11:16
Note: There is no other columns in the table T except Val column
Oct 5, 2019 11:15
+-----+-----+
| Val | Seq |
+-----+-----+
|   2 |   0 |
|   2 |   0 |
|   1 |   1 |
|   1 |   2 |
|   1 |   3 |
|   2 |   0 |
|   1 |   1 |
|   2 |   0 |
|   1 |   1 |
|   1 |   2 |
+-----+-----+
Oct 5, 2019 11:15
Expected results:
Oct 5, 2019 11:15
Oct 5, 2019 11:15
Anyone can help please to get the expected results?
 

 The Heap™ – Consultancy ©®

General on- and off-site discussion for dba.stackexchange.com....
Oct 5, 2019 11:14
Hey @PaulWhite
Oct 5, 2019 11:12
o/
Sep 13, 2019 12:15
I did in a comment ;)
Sep 13, 2019 12:14
Yup, but I won't guide someone to a wrong way
Sep 13, 2019 12:11
but not STRING_AGG(Tag, ',')
Sep 13, 2019 12:11
Something like, STRING_AGG(Tag, '","')
Sep 13, 2019 12:10
SO, used that for the tags of the question I think
Sep 13, 2019 12:09
Sep 13, 2019 11:48
@TomV SO always confuse me as such users do not point the OPs for the real problem
Sep 13, 2019 11:43
@ypercubeᵀᴹ Thnx
Sep 13, 2019 11:30
@ypercubeᵀᴹ in Oracle is?
Sep 13, 2019 11:30
@nuttyaboutnatty That's the full one
Sep 13, 2019 11:29
ServerName.DatabaseName.SchemaName.TableName
Sep 13, 2019 11:27
eh? a table name starts with a number?
Aug 12, 2019 08:44
Morning guys!
Jul 5, 2019 17:52
@War :D
Jul 5, 2019 10:24
Sure, it's already deleted Paul
Jul 5, 2019 10:06
Yeah, that's right
Jul 5, 2019 10:02
@PaulWhite Hey, hmmm maybe I'm wrong let me check
Jul 5, 2019 08:23
Jul 5, 2019 08:19
In SQL Server 2008 both will use the index, while if you test it on db<>fiddle none of them will use the index instead it's full table scan. — Sami 35 mins ago
Jul 5, 2019 08:18
It's all up to the optimizer
Jul 5, 2019 08:17
that makes the "Why second query doesn't use index? Because indexed column is wrapped in a function which prevents SQL Server from using index." in the answer wrong
Jul 5, 2019 08:15
@AndriyM Yeah, I just want to understand
Jul 5, 2019 08:13
eg: SELECT [Date] FROM Exams or SELECT 1 FROM Exams
Jul 5, 2019 08:13
Even so if we remove * the optimizer will decide to use the index
Jul 5, 2019 08:09
Jul 5, 2019 07:52
None of the queries will use the index, instead it's a full table scan (tested on db<>fiddle)
Jul 5, 2019 07:52
Both queries will use the index (tested on SQL Server 2008)
Jul 5, 2019 07:51
From this question on SO (SQL Server) don't you think guys that the right answer is "it depends on the optimizer"?
Jul 5, 2019 07:49
Morning o/
Jun 10, 2019 15:17
@Lamak I don't see you there much those days, think you 'll like to give that a chance :)
Jun 8, 2019 14:24
Try to run SSMS with the -log parameter and see the error. eg: C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe" -log D:\log.txtSami 1 hour ago
Jun 8, 2019 14:08
Afternoon
May 7, 2019 03:06
@PaulWhite I just reference ya here and if you have any comment about the A please do.
May 7, 2019 03:05
Morning!