Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Sql Problem!!

Sql Problem!!

Scheduled Pinned Locked Moved C#
databasehelpquestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nafiseh Salmani
    wrote on last edited by
    #1

    I write the following storePrpcedure:

    create PROCEDURE [dbo].[Ins_Products]
    -- Add the parameters for the stored procedure here
    @ProductName nvarchar(max),
    @ProductModel nvarchar(max),
    @ProductColor nvarchar(50),
    @ProductDescription nvarchar(max),
    @ProductPrice bigint,
    @ProductQuantity int

    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    

    declare @ProductID bigint;
    --set @ProductID=-1

    if Not Exists ( Select @ProductID = ProductID From Products 
    				Where ProductModel=@ProductModel)
    Begin
    	Insert Into Products (ProductName,ProductModel,ProductColor,ProductDescription,ProductPrice,ProductQuantity)
    	Values(@ProductName,@ProductModel,@ProductColor,@ProductDescription,@ProductPrice,@ProductQuantity)
        select @ProductID=@@Identity
    End
    else
    
    Begin
    	Update Products 
    		Set ProductName=@ProductName ,ProductModel=@ProductModel ,
    			ProductColor=@ProductColor,
    			ProductDescription=@ProductDescription,
    			ProductPrice=@ProductPrice,ProductQuantity=@ProductQuantity
    		where (ProductID=@ProductID)
    End
    

    return @ProductID
    END

    but it couse error:

    Msg 102, Level 15, State 1, Procedure Ins_Products, Line 26
    Incorrect syntax near '='.
    Msg 156, Level 15, State 1, Procedure Ins_Products, Line 33
    Incorrect syntax near the keyword 'else'.

    what should I do?!! ?!!!!!

    modified on Friday, May 1, 2009 4:10 AM

    A F 2 Replies Last reply
    0
    • N Nafiseh Salmani

      I write the following storePrpcedure:

      create PROCEDURE [dbo].[Ins_Products]
      -- Add the parameters for the stored procedure here
      @ProductName nvarchar(max),
      @ProductModel nvarchar(max),
      @ProductColor nvarchar(50),
      @ProductDescription nvarchar(max),
      @ProductPrice bigint,
      @ProductQuantity int

      AS
      BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

      -- Insert statements for procedure here
      

      declare @ProductID bigint;
      --set @ProductID=-1

      if Not Exists ( Select @ProductID = ProductID From Products 
      				Where ProductModel=@ProductModel)
      Begin
      	Insert Into Products (ProductName,ProductModel,ProductColor,ProductDescription,ProductPrice,ProductQuantity)
      	Values(@ProductName,@ProductModel,@ProductColor,@ProductDescription,@ProductPrice,@ProductQuantity)
          select @ProductID=@@Identity
      End
      else
      
      Begin
      	Update Products 
      		Set ProductName=@ProductName ,ProductModel=@ProductModel ,
      			ProductColor=@ProductColor,
      			ProductDescription=@ProductDescription,
      			ProductPrice=@ProductPrice,ProductQuantity=@ProductQuantity
      		where (ProductID=@ProductID)
      End
      

      return @ProductID
      END

      but it couse error:

      Msg 102, Level 15, State 1, Procedure Ins_Products, Line 26
      Incorrect syntax near '='.
      Msg 156, Level 15, State 1, Procedure Ins_Products, Line 33
      Incorrect syntax near the keyword 'else'.

      what should I do?!! ?!!!!!

      modified on Friday, May 1, 2009 4:10 AM

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      This is C# Forum. You should post the question in SQL Forum.

      cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net

      1 Reply Last reply
      0
      • N Nafiseh Salmani

        I write the following storePrpcedure:

        create PROCEDURE [dbo].[Ins_Products]
        -- Add the parameters for the stored procedure here
        @ProductName nvarchar(max),
        @ProductModel nvarchar(max),
        @ProductColor nvarchar(50),
        @ProductDescription nvarchar(max),
        @ProductPrice bigint,
        @ProductQuantity int

        AS
        BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;

        -- Insert statements for procedure here
        

        declare @ProductID bigint;
        --set @ProductID=-1

        if Not Exists ( Select @ProductID = ProductID From Products 
        				Where ProductModel=@ProductModel)
        Begin
        	Insert Into Products (ProductName,ProductModel,ProductColor,ProductDescription,ProductPrice,ProductQuantity)
        	Values(@ProductName,@ProductModel,@ProductColor,@ProductDescription,@ProductPrice,@ProductQuantity)
            select @ProductID=@@Identity
        End
        else
        
        Begin
        	Update Products 
        		Set ProductName=@ProductName ,ProductModel=@ProductModel ,
        			ProductColor=@ProductColor,
        			ProductDescription=@ProductDescription,
        			ProductPrice=@ProductPrice,ProductQuantity=@ProductQuantity
        		where (ProductID=@ProductID)
        End
        

        return @ProductID
        END

        but it couse error:

        Msg 102, Level 15, State 1, Procedure Ins_Products, Line 26
        Incorrect syntax near '='.
        Msg 156, Level 15, State 1, Procedure Ins_Products, Line 33
        Incorrect syntax near the keyword 'else'.

        what should I do?!! ?!!!!!

        modified on Friday, May 1, 2009 4:10 AM

        F Offline
        F Offline
        fly904
        wrote on last edited by
        #3

        Nafiseh Salmani wrote:

        select @ProductID=@@Identity

        Shouldn't that be:

        SET @ProductID = @@Identity

        My failometer is detecting vast quantities of FAIL! "Its SQL - hardly programming..." (Caslen)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups