Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bacm914
Starting Member
2 Posts |
Posted - 2012-05-28 : 09:46:31
|
I am trying to update the ID # in this table based on Type. I keep getting the error "Windowed functions can only appear in the SELECT or ORDER BY clauses." I've tried changing it based on other things I've read but I just can't get it to work. I'm sure it's something very simple. What is wrong with this code?:UPDATE LocSET Custom15 = ID,Id =CASE TypeWHEN 'FMTD' THEN '10-'WHEN 'FM8' THEN '20-'END + CAST(999+ROW_NUMBER( ) OVER (PARTITION BY Type ORDER BY Loc) AS VARCHAR(15))Thanks in advance!! |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-28 : 10:01:00
|
[code]update lset Custom15 = ID ,Id = NEW_IDfrom( select *, NEW_ID = CASE Type WHEN 'FMTD' THEN '10-' WHEN 'FM8' THEN '20-' END + CAST(999+ROW_NUMBER( ) OVER (PARTITION BY Type ORDER BY Loc) AS VARCHAR(15)) from Loc) l[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
bacm914
Starting Member
2 Posts |
Posted - 2012-05-28 : 10:29:43
|
Thanks a bunch! Worked perfectly!! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-28 : 10:47:59
|
Welcome KH[spoiler]Time is always against us[/spoiler] |
|
|
pkokil
Starting Member
1 Post |
Posted - 2013-04-17 : 06:15:01
|
Very useful post...Thanks a lotttttt...... |
|
|
|
|
|