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

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

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
Post a Comment