Not sure if I should use a cursor in Microsoft SQL Server 2008 R2 -


i have problem here. thing have table called mostep, in table there's column called moid. need check repeated values, mean example, in table there these values:

10, 9, 8, 6, 9, 5, 2 10 

i need check values of moid in table , 2 things, details of conditions rather irrelevant questions i'll omit them:

  1. if value appears once, each of them.
  2. if value appears more once, else each of them.

i know how check repeated , not repeated values using

count(moid) 

however don't know how check in same query , make efficient.

i thinking in using 2 cursors, 1 stores repeated values , fetch each row, , same thing non repeated values. i've heard cursors not best option

i thinking in doing if or case conditions within select i'm not sure how of it.

if me i'll appreciate it

doesn't sound there's reason use cursor this. can use count() over() , case efficiently:

;with cte (select *,count(moid) over(partition moid) moid_ct               mostep) select moid       ,case when moid_ct = 1 'something' else 'somethingelse' end cte 

demo: sql fiddle


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -