sql server - how to loop through table and set cell equal to an incremented value in sql -


i have table of users , if companyid input equal companyid user name shown , other names shown xxxxx. need way set "name"(literally word name) , incremented number how ever many there are.

    select       case when t1.companyid = @id t1.name else      (     'xxxxx'     )     end name 

with input 148 shows

enter image description here

i want show this, , on more names(name3, name4, etc..):

enter image description here

with foo being name of table, works (see sqlfiddle) :

set @id = 142; set @i = 0; select       companyid,     case when foo.companyid = @id          foo.name          else (concat('name',@i := @i+1))     end name foo; 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -