sql server - SQL procedure select -


i write procedure database return select data database tournaments plus bool parameter. if user registered, return true.

call:

exec tournamentswithloggeduser @user = 'asd123' 

procedure:

create procedure [dbo].[tournamentswithloggeduser]     @user  nvarchar(128)     select          t.id, t.info, bit(r.id)                tournaments t     left join          registrations r on  t.id = r.tournamentid             r.userid null or r.userid = @user      return 

it mean like

1, 'some info', true //1 2, 'some info2', false //2 

you looking query

select t.id,         t.info,         cast (case                 when r.userid not null 1                 else 0               end bit) isregistered    tournaments t         left join registrations r                on t.id = r.tournamentid                   , r.userid = @user  

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -