Wednesday, October 6, 2010

storing the value into a variable within a select query

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
alter PROCEDURE Pr_StoringValue
AS
declare @name varchar(max)
declare @name1 varchar(max)
BEGIN

create table #user(id integer IDENTITY(1,1),
username varchar(max)
)
insert into #user(username) values ('Nitin')
insert into #user(username) values ('Anoop')
insert into #user(username) values ('Sagar')

  select @name = username from #user
  select @name
  update #user set username = 'ABC' where id=3
  select @name1 = username from #user
  select @name1

select * from #user
END
GO

-----------------------------------------------------

Execute Here...

EXEC Pr_StoringValue

No comments: