Hello I am new in creating stored procedure can you help me how to do this. Error: Incorrect syntax near the keyword 'AS'. Must declare scalar variable @Serial.
CREATE PROCEDURE sp_SIU
-- Add the parameters for the stored procedure here
@Serial varchar(50),
@Part varchar(50),
@Status varchar(50),
AS
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
/*SET NOCOUNT ON;*/
-- Insert statements for procedure here
--where in my form if i enter serial number it will show select values
Select SerialNumber,PartNumber,Status from Table1 where SerialNUmber = @Serial
--Then if is correct it will Update Status on combobox
Update Table1 SET
Status=@Status
where SerialNumber=@SerialNumber
--then Insert Serial Number,Parnumber to Table 2
DECLARE @Count int
select @Count = Count(SerialNumber) from Table1 WHERE SerialNumber = @Serial
IF @Count = 0
BEGIN
INSERT INTO Table2 (SerialNumber,PArtNumber)
VALUES
(@Serial, @Part)
END
RETURN @Count
RETURN
Edit: Moved Updated info posted as an answer into Question
Oops my post is not that kind a miss. It is possible to join this 3 sql string in one stored procedure?
Scenario:
{
What i have to do in my form is that i will enter serial number to txtserial.text
by using the select sql it will show serialnumber,partnumber
and status
on lblserial.text,lblpartnumber.text
and lblstatus.text
.
And i will compare:
txtserial.text == lblserial.text
txtpartnumber.text == lblpartnumber.text
for my error handler.
{
Select SerialNumber,PartNumber,Status from Table1 where SerialNUmber = @Serial
}
Then if they are equal then: I will update my Status from cbostatus.text if serial and part is correct then use sql upate.
{
Update Table1 SET
Status=@Status,
Modifiedby=@username,
DateModified=@Date
where SerialNumber=@Serial
}
Then insert serialnumber, using sql insert to another table.
{
INSERT INTO Table2 (SerialNumber,DateCreated,Createdby)
VALUES
(@Serial,@date,@username)
}
something likethis. ")