Click here to Skip to main content
15,887,998 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Dear All,
I have created following StoredProcedure in SQLServer2008
SQL
Create Procedure tbl_Master_InsertOrUpdate(@MasterID nvarchar(20),@Category_Name nvarchar(20),@Category_Image image,@Operating_Hours time,@NonOperating_Hours time)
As
Begin
If Not Exists(Select MasterID from tbl_Master where MasterID=@MasterID)
Insert into tbl_Master(MasterID,Category_Name,Category_Image,Operating_Hours, NonOperating_Hours) values(@MasterID,@Category_Name,@Category_Image, @Operating_Hours,@NonOperating_Hours)
Else
Update  tbl_Master Set Category_Name=@Category_Name,Category_Image= @Category_Image,Operating_Hours=@Operating_Hours,NonOperating_Hours=@NonOperating_Hours Where MasterID=@MasterID
End


I have compiled this & I am trying to execute this Procedure as follows
Exec tbl_Master_InsertOrUpdate 1 Sandwich null null null
But i got the following error
Incorrect Syntax near the keyword null
But the statement seems to be correct..
Can anybody resolve this issue..
Posted
Updated 7-Mar-12 3:53am
v2

You need commas to separate your variables and string variables need to be quoted.

SQL
Exec tbl_Master_InsertOrUpdate '1', 'Sandwich', null, null, null


In SSMS, right mouse on your stored procedure and choose 'Script Stored Procedure as' - 'Execute To' - 'New Query Editor Window'

The correct execution syntax will be displayed for you
 
Share this answer
 
You Can To Modify your proc to

CREATE PROCEDURE tbl_Master_InsertOrUpdate
    (
      @MasterID NVARCHAR(20) = null ,
      @Category_Name NVARCHAR(20)= null ,
      @Category_Image IMAGE = null,
      @Operating_Hours TIME = null,
      @NonOperating_Hours TIME = null
    )
AS 
    BEGIN
        IF NOT EXISTS ( SELECT  MasterID
                        FROM    tbl_Master
                        WHERE   MasterID = @MasterID ) 
            INSERT  INTO tbl_Master
                    ( MasterID ,
                      Category_Name ,
                      Category_Image ,
                      Operating_Hours ,
                      NonOperating_Hours
                    )
            VALUES  ( @MasterID ,
                      @Category_Name ,
                      @Category_Image ,
                      @Operating_Hours ,
                      @NonOperating_Hours
                    )
        ELSE 
            UPDATE  tbl_Master
            SET     Category_Name =ISNULL( @Category_Name, Category_Name),
                    Category_Image =ISNULL( @Category_Image ,Category_Image),
                    Operating_Hours = ISNULL(@Operating_Hours ,Operating_Hours),
                    NonOperating_Hours = ISNULL(@NonOperating_Hours,NonOperating_Hours)
            WHERE   MasterID = @MasterID
    END


and to Excite Code Try

tbl_Master_InsertOrUpdate '1', 'Sandwich', null, null, null
 
Share this answer
 

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