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 8728727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:42:17+00:00 2026-06-13T08:42:17+00:00

i have a stored procedure UPDATE tblTime SET TimeOut = DATEADD(HOUR,8,TimeIn) WHERE tId =

  • 0

i have a stored procedure

UPDATE tblTime
SET TimeOut = DATEADD(HOUR,8,TimeIn)
WHERE tId =
( 
   SELECT MAX(tId)
   FROM tblTime
   WHERE UserId = 3571
)

although there’s no question really, in that case if it did succeed in this query

cause even if the field is empty or if it has value,
it will in this case succeed

but i do need it for future other queries… and also ,
in this case i want the C# code to report
not only that it was requesting query to be execute – meaning it did happen,

but to get an actual answer from sql server
as a return value that c# could use or turn into Boolean

  • 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-06-13T08:42:18+00:00Added an answer on June 13, 2026 at 8:42 am

    i have managed to do somthing about this so i can specify a condition inside sql server stored proc

    declare an OUTPUT variable(PARAMETER) then

    set its value to say 1 if condition is met and -1 if not

    then
    in c# set a function as follows
    in this example outpout parameter is named ERROR

       public static int UpdateTblViaStoredPRoc(string SPname, int UserID)
            {
                int message = 0;
                using (SqlConnection con = new SqlConnection("server=(local);Initial Catalog=****DBNAME HERE***;Integrated Security=True"))
                {
    
                    con.Open();
    
                    SqlCommand cmd = new SqlCommand(SPname, con);
    
                    cmd.CommandType = CommandType.StoredProcedure;
    
                    cmd.Parameters.AddWithValue("@Uid", UserID);
    
                    cmd.Parameters.Add("@ERROR", SqlDbType.Int);
    
                    cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
    
                    cmd.ExecuteNonQuery();
    
                     message =(int) cmd.Parameters["@ERROR"].Value;
    
                    con.Close();
                }
                return message;
            }
    

    stored proc is then allways following the same pattern

    declare ERROR parameter, set a condition to output the ERROR accordingly :

    ALTER PROCEDURE [dbo].[nameofProc]
    @UId Int, @ERROR int OUT
    AS
    
    BEGIN    
    
    SET NOCOUNT ON;
    
    DECLARE @TimeOtVal varchar(50)
    set @TimeOtVal = (SELECT CASE WHEN [TimeOut] IS NULL THEN '' ELSE CONVERT(NVARCHAR,[TimeOut]) END FROM tblTime WHERE tId = ( SELECT MAX(tId) FROM tblTime WHERE UserId = @UId))
    
    IF (@TimeOtVal = '') -- condition for the update 
    
    BEGIN -- now action is taken if condition is met
    
        SET NOCOUNT ON;
        UPDATE tblTime  SET TimeOut = DATEADD(HOUR,8,TimeIn) WHERE tId = ( SELECT MAX(tId) FROM tblTime WHERE UserId = @UId)        
             SET  @ERROR = 1
    END
     else
    
         BEGIN -- Other wise , if condition isnot met 
    
             SET  @ERROR = -1
    
         END
    
    END
    

    so it does what you want only if you allowed it by the condition
    then reports the action so you can handle it in program code behind .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that says update table1 set value1 = 1 where
Say I have a stored procedure consisting of several separate SELECT, INSERT, UPDATE and
I have this stored procedure which get data from excell and then update status:
I have set up a stored procedure to update a database on my linked
I have a stored procedure with a select and an update. I would like
I have a MySQL stored procedure like this UPDATE `Discounts` SET `Occupation`=occupation, `Organization`=organization, `LastName`=lastName,
I have a stored procedure GetReportItems : GetReportItems @ItemId varchar(max) SELECT rt.ReportName, rt.ReportId, rg.OriginatedFrom
I have a stored procedure which update a table based on such calculation and
I have a stored procedure which is called inside a trigger on Insert/Update/Delete. The
I have to write a update stored procedure. I will be asking paramters for

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.