Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:11:48+00:00 2026-05-26T20:11:48+00:00

I am trying to make one stored procedure only in SQL Server that lets

  • 0

I am trying to make one stored procedure only in SQL Server that lets the user to choose if he/she wants to add or update a record. Below is my code for my stored pro:

CREATE PROCEDURE Sproc_INSERTUPDATE_tblProducts

    @ProductID bigint,
    @ProductName varchar(50),
    @Description varchar(50),
    @Price money,
    @DateCreated datetime,
    @DateUpdated datetime,
    @Choice bit output

AS
BEGIN

    Select @Choice
    If @Choice = 0
    Begin
    Insert into tblProducts (
                          ProductID, 
                          ProductName, 
                          Description, 
                          Price, 
                          DateCreated, 
                          DateUpdated)
    values (@ProductID, 
                @ProductName, 
                @Description, 
                @Price, 
                @DateCreated, 
                @DateUpdated)
    Select * from tblProducts
    End
    Else If @Choice = 1
    Begin
    Update tblProducts Set ProductID = @ProductID,
                           ProductName = @ProductName,
                           Description = @Description,
                           Price = @Price,
                           DateCreated = @DateCreated,
                           DateUpdated = @DateUpdated
    Select * from tblProducts
    End
    Else
    Begin
    Print 'Invalid choice. Please choose 0 or 1 only.'
    End

END
GO

And here is my code for executing the stored pro I made:

USE StoreDB

Execute Sproc_INSERTUPDATE_tblProducts 4, 'Lotus', 'Flower', 85, GetDate, GetDate, 0

I don’t encounter any errors with my stored pro but when I try to execute using a new query, I get this error message:

GetDate(): Error converting data type nvarchar to datetime.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:11:48+00:00Added an answer on May 26, 2026 at 8:11 pm

    You cannot pass a function such as getdate() into a stored proc. Declare a datetime variable and use that instead.

    Declare @now datetime = getdate();
    Execute Sproc_INSERTUPDATE_tblProducts 4, 'Lotus', 'Flower', 85, @now, @now, 0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a program in Visual C# that has my one created
I am trying to make a boolean test so that if one of the
I am trying to make a jquery menu that when I click on one
I'm trying to make an overlay with thickbox... it only allows one line captions...
I'm trying to write a stored procedure that will return two calculated values for
While trying to make one of my python applications a bit more robust in
I'm trying to make one word (variable) of a message box bold in my
I'm trying to make a one to one relationship in a MySQL DB. I'm
I'm trying to make an update of one project of mine, but i don't
I'm trying to make an address redirect to another one without actually changing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.