Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I want to create one stored procedure to insert data into a table of SQL Server 2005.

Thanks in advance!
Posted
Updated 14-Mar-11 12:09pm
v2
Comments
Toli Cuturicu 14-Mar-11 18:15pm    
You have my blessing. Create it!
However, what was the question?

The syntax is as follows:
SQL
CREATE PROCEDURE SomeStoredProcedure
    @SomeParam int,
    @AnotherParam int
AS
BEGIN
    INSERT INTO SomeTable(SomeColumn, AnotherColumn) VALUES(@SomeParam, @AnotherParam)
END
 
Share this answer
 
Suppose your table name is T1,which has two columns Name and Designation.
Procedure Name is InsertIntoT1.
SQL
Create proc InsertIntoT1(@Name varchar(50),@Designation varchar(50))
as
begin
insert into T1(Name,Designation)values(@Name,@Designation);
end


/*How to call the stored procedure*/
SQL
exec InsertIntoT1 'Sajid Ahmed Shahsroha','Team Lead/Sr.Software Engineer'
 
Share this answer
 
v2
Example:
SQL
create procedure Proc_Name

@Column1Value DataType,
@Column2Value DataType
as
begin
insert into TableName 
 (
 Column1,
 Column2
 ) 
 values
 (
 @Column1Value, 
 @Column2Value 
 )
end

Execute the Stored Procedure By Using the following Statement:
SQL
exec Proc_Name 'TestValue1','TestValue2'


Thanks,
Raja.S
 
Share this answer
 
v2
Comments
shwetaGupta31 26-Jun-13 6:45am    
create procedure Sp_ADDBLOG
@varCategoryId bigint,
@varBlogHeader nvarchar(50),
@varBlogContent nvarchar(max),
@varAlumniId bigint,
@varRole nvarchar(50),
@varStatus nvarchar(50)
AS
BEGIN
insert into blog
(
category_id,blog_header,blog_content,alumni_id,role,status,created_date,created_time
)
values
(
@varCategoryId,@varBlogHeader,@varBlogContent,@varAlumniId,@varRole,@varStatus,getdate(),CURRENT_TIMESTAMP
)
END


when i execute this-
Error shows
Msg 273, Level 16, State 1, Procedure Sp_ADDBLOG, Line 10
Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.

can anybody solve this???
SQL
create PROCEDURE module_add
	-- Add the parameters for the stored procedure here
	@Module varchar(50),
	@ModuleId int output
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    -- Insert statements for procedure here
	insert into bugreporter_Module(Module) values(@Module);
	if(scope_identity()>=1)
	select @ModuleId = SCOPE_IDENTITY();
	else
	select @ModuleId=0;    
	return @ModuleId;  
END
 
Share this answer
 
v2
CREATE PROCEDURE dbo.MangeMember @check nvarchar (1), @user_name nvarchar (50), @password nvarchar (50), @full_name nvarchar (50),
@email nvarchar (50),
@phone nvarchar (12),
@gender nchar (1),
@question nvarchar (20),
@answer nvarchar (10),


AS
if @check = 'a'
begin

INSERT INTO Member
("user_name", "password", "full_Name", "email", "phone", "gender", "question", "answer")
VALUES (@user_name, @password, @full_name, @email, @phone, @gender, @question, @answer)
end
 
Share this answer
 
Comments
Ashraf Abd ElRahman 14-Apr-15 15:26pm    
Why every time send me error message incorrect syntax near as sql 2005
ZurdoDev 14-Apr-15 16:02pm    
1. Why did you post this as an answer?
2. Why did you post this to an old question?
3. Why did you then ask yourself a question?
4. What are you doing?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900