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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:23:24+00:00 2026-05-25T21:23:24+00:00

I have an SQL command I am attempting to execute. The syntax is as

  • 0

I have an SQL command I am attempting to execute.

The syntax is as follows

    Public Shared Function CanRaiseWorkOrder(connection As IDbConnection, ProductID As Guid) As Boolean
        Using sqlCmd As IDbCommand = connection.CreateCommand
            With sqlCmd
                .CommandTimeout = 30
                .CommandType = CommandType.Text
                .CommandText = "DECLARE @CanRaiseWorkOrder BIT, @WorkOrderQtyCount INT, @ProductAvailCount INT SET @WorkOrderQtyCount = (SELECT SUM(Qty) FROM WorkOrder WHERE ProductID = @ProductID AND WorkOrder.Status <> 4) --4 = Voided SET @ProductAvailCount = (SELECT Qty FROM Product WHERE ProductID = @ProductID) IF @WorkOrderQtyCount < @ProductAvailCount BEGIN SET @CanRaiseWorkOrder = 1 END ELSE BEGIN SET @CanRaiseWorkOrder = 0 END SELECT @CanRaiseWorkOrder AS CanRaiseWorkOrder"

                Dim params As New List(Of IDbDataParameter)({
                                                               ProductDAL.CreateTSqlParameter("@ProductID", DbType.Guid, ProductID)
                                                            })

                .Parameters.AddRange(params)

                Return .ExecuteScaler(Of Boolean)()
            End With
        End Using
    End Function

As you will probably notice there is some customization there in regards to how the parameters are created and the command executed but you can assume those aspects of the system work as required (We have a significant amount of code that functions correctly using those methods).

I will probably get some people asking why this is not a stored procedure and the answer is “because my boss said so”.

I have run SQL profiler and here is the output that this query actually generates.

exec sp_executesql N'DECLARE @CanRaiseWorkOrder BIT, @WorkOrderQtyCount INT, @ProductAvailCount INT SET @WorkOrderQtyCount = (SELECT SUM(Qty) FROM WorkOrder WHERE ProductID = @ProductID AND WorkOrder.Status <> 4) --4 = Voided SET @ProductAvailCount = (SELECT Qty FROM Product WHERE ProductID = @ProductID) IF @WorkOrderQtyCount < @ProductAvailCount BEGIN SET @CanRaiseWorkOrder = 1 END ELSE BEGIN SET @CanRaiseWorkOrder = 0 END SELECT @CanRaiseWorkOrder',N'@ProductID uniqueidentifier',@ProductID='0908C780-763F-4CE6-B074-CEC01F4451B4'

Running the code in query analyser (when I originally created it) works fine but if I run the above query as outputted from the SQL command all I get is “Command(s) completed successfully.“

Any ideas?

  • 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-25T21:23:24+00:00Added an answer on May 25, 2026 at 9:23 pm

    Figure I’ll make it an answer, but also wanted to make sure I was accurate (considering how long I’ve been up now :grin:).

    From what I can see (and this is probably due to condensing your statement for the sake of making it a one-liner in a code file) you have a comment declaration in the middle of your statement:

    --4 = Voided [...]
    

    What’s happening is you’re executing only your DECLARE and first SET command (which are done without error) but the rest of your statement is being ignored because it follows the comment declaration (--).

    Make sure if you do condense your query that you remove commented lines. Once they’re on one line, SQL doesn’t care and WILL ignore anything past the --.

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

Sidebar

Related Questions

I have created a function that takes a SQL command and produces output that
I have an UPDATE sql command that modifies a Date/Time field in a particular
Say I have a table called myTable. What is the SQL command to return
We have an application that installs SQL Server Express from the command line and
I have used an update command to update the whole table in an Sql
I have the following sql command through code and because the parameter contains a
Say I have the following Linq 2 SQL command; ItemsRepository.All().Where(r => r.type == myType);
I have a hard time telling what operations in linq cause a SQL command
Suppose i have this sql statement and I have executed a sql command to
If I have a sql table that contains ProductID Price Date and I wish

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.