SQL Script | ROW_Number & CASE WHEN (1 Viewer)

CharlieWh

New member
Local time
Yesterday, 23:25
Joined
Oct 12, 2014
Messages
4
I have a Select & Insert Into statement that I am trying to build and due to duplicates (that must not be removed) I am attempting to use row_number within a case statement, so that when the result of row_number = 1 then I specify the vault of As WsID as one thing and case row_number is grater than 1 then append row_number vault to the text.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:25
Joined
May 7, 2009
Messages
19,231
can a Total (aggregate) query do it?
 

CharlieWh

New member
Local time
Yesterday, 23:25
Joined
Oct 12, 2014
Messages
4
Code:
A bit like this, but this is no where near

d.c1alias
        ROW_NUMBER() OVER(PARTITION BY d.c1alias ORDER BY d.c1alias)
        CASE
        WHEN d.c1alias = 1 THEN 'Original'
        WHEN d.c1alias = >1 THEN 'Not Original'
        END
        AS Wsid,
 

Minty

AWF VIP
Local time
Today, 07:25
Joined
Jul 26, 2013
Messages
10,366
What version of SQL Server are you using?
 

CharlieWh

New member
Local time
Yesterday, 23:25
Joined
Oct 12, 2014
Messages
4
Got it!

Code:
CASE
WHEN ROW_NUMBER() OVER(PARTITION BY d.c1alias ORDER BY d.c1alias) = 1 THEN concat(''PROP.'', d.c1alias)
ELSE concat(''PROP.'', d.c1alias, ''_'', ROW_NUMBER() OVER(PARTITION BY d.c1alias ORDER BY d.c1alias))
END As Wsid,
 

Users who are viewing this thread

Top Bottom