Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use pr_example;
- go
- create proc ShowPhoneCount
- @name varchar(20)
- as
- begin
- declare @count int, @i int, @id_ph int, @p_number varchar(11);
- set @count = (select count(p.number) from users u, phones p where u.id = p.u_id and u.name = @name);
- set @id_ph = 0;
- set @p_number = '';
- set @i = 1;
- print N'У пользователя ' + @name + ' ' + convert(varchar(11), @count) + ' номеров телефонов';
- while @i <= @count
- begin
- set @i = @i + 1;
- set @id_ph = (select top(1) p.id from phones p, users u where u.id = p.u_id and u.name = @name and p.id <> @id_ph);
- set @p_number = (select p.number from phones p, users u where u.id = p.u_id and p.id <> @id_ph and u.name = @name);
- print N'Его номер телефона: ' + @p_number;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement