May 26, 2010 at 4:59 am
Hi ,
this is my store procedure , i have an error message : Incorrect syntax near the keyword 'where'.
would you please help me?
ALTER PROCEDURE [dbo].[InsertEmployee]
@VarEmp_Id int,
@VarEmp_Codemeli nvarchar(50),
@VarEmp_Fathersname nvarchar(50),
@VarEmp_Shomareshenasname int,
@VarEmp_Birthdate nvarchar(50),
@VarEmp_Mahalesodoor nvarchar(50),
@VarEmp_Married bit,
@VarEmp_Single bit,
@VarEmp_Male bit,
@VarEmp_Female bit,
@VarEmp_Madrak nvarchar(50),
@VarEmp_Reshte nvarchar(50)
AS
BEGIN
insert into Employee (Emp_Codemeli,Emp_Fathersname,Emp_Shomareshenasname,Emp_Birthdate,Emp_Mahalesodoor,Emp_Married,Emp_Single,Emp_Male,Emp_Female,Emp_Madrak,Emp_Reshte)
values (@VarEmp_Codemeli,@VarEmp_Fathersname,@VarEmp_Shomareshenasname,@VarEmp_Birthdate,@VarEmp_Mahalesodoor,@VarEmp_Married,@VarEmp_Single,@VarEmp_Male,@VarEmp_Female,@VarEmp_Madrak,@VarEmp_Reshte)
where Emp_Id=@VarEmp_Id
END
May 26, 2010 at 5:04 am
Insert... values cannot have a where clause, as there's no query to apply that where to.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 26, 2010 at 6:36 am
O.K
i want to insert a some fileds to a record wich is in a database (i saved it before), i want if the primary key of that record equal with a variable , i can put those new fields.
May 26, 2010 at 7:16 am
Don't understand. More details please, with table definition would be good.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 26, 2010 at 7:20 am
replace Values with select, remove brackets "()"
You don't nedd use from in this query.
May 26, 2010 at 7:57 am
Tomasz Jureczko (5/26/2010)
replace Values with select, remove brackets "()"You don't nedd use from in this query.
Replacing values with select will still result in a syntax error, as the where clause will still be invalid.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 26, 2010 at 8:12 am
Like Gail, I'm not entirely certain what you're after. I think you're looking for something like this: -
UPDATE Employee
SET emp_codemeli = @VarEmp_Codemeli,
emp_fathersname = @VarEmp_Fathersname,
emp_shomareshenasname = @VarEmp_Shomareshenasname,
emp_birthdate = @VarEmp_Birthdate,
emp_mahalesodoor = @VarEmp_Mahalesodoor,
emp_married = @VarEmp_Married,
emp_single = @VarEmp_Single,
emp_male = @VarEmp_Male,
emp_female = @VarEmp_Female,
emp_madrak = @VarEmp_Madrak,
emp_reshte = @VarEmp_Reshte
WHERE emp_id = @VarEmp_Id
Let us know if that was it.
May 26, 2010 at 8:33 am
ok, I was blind , I thought you write update.
Try this (or play with loop if you want):
create table aaaa( a int, b int)
declare @cond int
set @cond = 1
insert into aaaa(a,b) select @cond, @cond + 1 where @cond > 3
set @cond = 2
insert into aaaa(a,b) select @cond, @cond + 1 where @cond > 3
set @cond = 3
insert into aaaa(a,b) select @cond, @cond + 1 where @cond > 3
set @cond = 4
insert into aaaa(a,b) select @cond, @cond + 1 where @cond > 3
while inserting you don't have .... "cursor" on your data -> perhaps write trigger to control.
What are you want really to do
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply